Skip to content

Instantly share code, notes, and snippets.

@dbu
Created January 14, 2026 13:43
Show Gist options
  • Select an option

  • Save dbu/d129dba9c3912edb50ba4c8bec3694e8 to your computer and use it in GitHub Desktop.

Select an option

Save dbu/d129dba9c3912edb50ba4c8bec3694e8 to your computer and use it in GitHub Desktop.
Configure commonmark extensions in twig extra bundle

It is actually possible to include and configure commonmark extensions when using the markdown features of Twig Extra Bundle.

The documentation at https://twig.symfony.com/doc/3.x/filters/markdown_to_html.html does not explain how, so let me show it here.

We need to define a tagged service for the extension and we need to specify the configuration.

⚠️ beware, there is no validation of configuration, neither in Twig Extra Bundle nor in Commonmark that receives the configuration. If your configuration is in the wrong place or has typos, it will simply not be taken into account.

twig_extra:
commonmark:
external_link:
open_in_new_window: true
noopener: external
noreferrer: external
services:
League\CommonMark\Extension\ExternalLink\ExternalLinkExtension:
tags: ['twig.markdown.league_extension']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment