Introducing CommonmarkBundle

Published on 10/26/20 at 8:05 PM. Updated on 10/31/20 at 4:55 PM.

A Symfony bundle for an easy league/commonmark integration.

Introducing CommonmarkBundle

I recently published a Symfony bundle (my first one), so I'm presenting it to you today.

If you just want to see the code: AymDev/CommonMarkBundle.

The idea

I write a lot of MarkDown content on my website: courses and blog posts. It's convenient, and I may not be the only one to think so as it's used on GitHub, StackOverflow, ...
Until now I was using ParseDown (which is great and easy to use), but I wanted to make something specific: make external links open in a new tab.

Looking for solutions

While searching, I stumbled upon an extension: taufik-nurrohman/parsedown-extra-plugin.
But this library isn't available on Packagist and does not respect semantic versioning. I finally started to look for ParseDown alternatives.


I quickly found PHP League's library: CommonMark. It's easy to use too, but it provides extensions including one about external links !
I made my choice. But then, how to integrate it within Symfony ?

Services and bundles

As of the library's basic usage, I thought I could add manual service configuration to my services.yaml. But with the multipleextensions and the different configurations I could do, I thought that a bundle would make things easier.

The issue: there's no official bundle, and those I found were using league/commonmark in v0.x, or weren't available on Packagist, or didn't allow for multiple "converters".

Conclusion: build my own bundle.



I never built a bundle before. I read Symfony's documentation about it, began coding, to end up crying during the bundle's configuration class.
I then took a course on how the service container works, how it is compiled in cache, the bundle extensions, compiler pass, ...
And I finally came to the end despite some errors !


Here's AymDev/CommonMarkBundle !
You will find the complete documentation in the README. It solves what I did not find elsewhere:

  • installation via Composer: aymdev/commonmark-bundle
  • requires league/commonmark in v1.5 minimum
  • allows multiple converters configuration
  • provides converters by autowiring if you need them
  • provides a Twig filter


If you read until there, know that this post has been converted by a converter configured by the bundle, another one is converting the comments.
It is still important to mention the tools I use to render my content:

Give me a feedback if you try the bundle !

Comments: 2

K4gur0 16/01/2021 - 02:58
Félicitation Aymeric pour ton first bundle ! Ça me donne envi de m'y lancer, un de ces 4 je publierais les miens aussi :p
Ça mérite une étoile en plus sur ton Repo Github
Good job :)

bogdanradoi 04/11/2020 - 10:37
Hello Aymeric, ça à l'air TOP ton bundle Markdown. Je vais le tester. :)

Robot invasion coming from