I’m working on a project where we want to make some of the content available in multiple formats (HTML, PDF, and plain text). I have the plain text version working ok but would like to manage it better.
The solution I came up with (after trying a few different options) is to apply a series of regular expressions to the markdown text for the page, since the markdown is the closest to the output we want. (I first tried applying it to the plain text content, but that lost important formatting, particularly with lists.)
I’m ok with this approach, but was hoping for a better way to manage the regular expressions. I thought I ought to be able to put them in a data file (where I could add comments to document them and more easily add new ones), but when I tried that I ran into two problems:
The regular expressions that worked in the template didn’t seem to match anymore; is the escaping different?
I think I need to use Scratch to store and update the modified content after each regex is applied, but it didn’t seem like that was working (although difficult to tell since my regexes were not matching).
Thanks for the suggestion! I wasn’t aware of custom render hook templates. It looks like it is pretty powerful but doesn’t support all of the features we need to handle.