Pandoc and lua filters

For my work on, I opted to use hugo and the hugo-book theme. Initially, this proved a super useful strategy. But it created a bit of a problem for generating PDFs, specifically when using some custom shortcodes. Specifically, I planned on using pandoc to manage the PDF and EPUB creation, but when processing the markdown with shortcodes, pandoc didn’t understand these shortcodes.

The solution, apparently, is to use pandoc filters. Because there’s a python implementation, I attempted that first. But there was a weird recursion issue. Fortunately, lua filters didn’t have that recursion issue. So, I used a lua filter.

Here’s my gist with the lua filter. The key approach, though, is to walk through each Para element in the file and look for text that matches the {{< foo bar >}} shortcode format and replace the text inside with the desired output.