Obsidian Support for League CommonMark

Published in PHP on Nov 28, 2022

I've been using Obsidian for some months now for personal knowledge management, among other things.

One of those other things is keeping notes for a Werewolf: The Forsaken 2E game that I play in every couple of weeks. We reached a point in the game where I became the designated note-taker for the group. However, none of the others use Obsidian, which it made it a bit difficult to share my notes with them in a user-friendly form.

I'd used the league/commonmark package to build the previous iteration of the site you're reading now. I wondered if I couldn't leverage it again to create a solution for this present predicament.

Initially, I wrote a quick-and-dirty script that transformed the Markdown source file contents prior to using league/commonmark to convert them to HTML. However, that solution was fairly hacky and its output wasn't very good in some cases.

A quick skim of Packagist results for a better solution didn't yield anything specific to my use case, so I took it upon myself to write my own extension for league/commonmark: elazar/league-commonmark-obsidian. (In the process, I even managed to submit a small fix to related league/commonmark documentation that was merged!)

In addition to the extension itself, the library includes a simple stock conversion script ./bin/obsidian-to-html and a Converter class used by that script that can be used in custom conversion scripts for additional customization of the output.

While I suspect that this package has a rather niche audience, I hope it proves useful to someone else. I've already replaced my own script with one that uses this extension and I'm fairly happy with the results.