Building my own static site generator, part 5: replacing Ink and Splash

In part 3 I wrote about my thoughts on Saga so far, and a big take-away were the problems I found with the third party dependencies I initially chose for my static site generator Saga: Ink and Splash for the Markdown parsing and code highlighting, and the HTML template language Stencil.

In the past few days I’ve spent quite a lot of time looking at multiple Markdown libraries written in Swift, but sadly not a single one fulfilled all the requirements, like the parsing of metadata contained within a Markdown file or the ability to easily modify the output via extensions. The best Markdown parsers seemed to be written in Python, so I decided to use PythonKit and wrote Swift wrappers around two promising Python libraries: SwiftMarkdown which wraps Python-Markdown, and SwiftMarkdown2 which wraps python-markdown2. It’s the first of these that I ended up using in Saga, because it was incredibly easy to extend that parser with my own extensions. For example, I want to strip the first title out of the Markdown “body”, so that you can generate a summary from the body for example, or render the published date between the title and the body, like I do right here on this website.

It’s not ideal that now Saga depends on Python and Python-Markdown, but the results simply speak for themselves: it’s just a league above other parsers. If I find a pure Swift parser that can match this output, I’ll gladly change over. I did keep my old Markdown reader that uses Ink and Splash as a separate plugin which is easily installed and used instead of the new reader. That’s a great thing about Saga; it’s very easy to extend!

I’m happy to say that Saga is now able to generate my website without any meaningful changes in output. Even the old templates were ported over almost as-is. You can see this Pull Request for details. Of course I’m still planning to replace Stencil with something completely different, so that PR will definitely grow to have bigger changes in the future.

Did you like this article, spot an error, or have other feedback? Please let me know on Twitter. If you liked this article, please consider buying me a coffee.