Here’s a trick for Marked 2 that allows you to keep a custom export format updated every time you save your file and update the Marked preview. I designed it specifically for updating a Lyx file, but you can use it with any secondary processor that doesn’t necessarily output HTML.
Marked’s Custom Preprocessor functionality allows you to do some work with the Markdown file after Marked has compiled any includes and custom syntax, but before it runs the Markdown processor (or other Custom Processor). All the preprocessor has to do is return plain text ready for conversion, so anything else that happens between is fair game.
If a script returns “NOCUSTOM” on STDOUT (as the one below does), Marked ignores the output entirely, so you don’t even have to echo the original back out. This is especially handy with custom processors as it allows them to check for certain conditions before processing a file, and cancel the operation if it’s not needed.
This code will take the open file and determine its directory path and filename, creating a compiled Markdown version and Lyx companion file every time the source file or any included files update. Save it as a script, make it executable, and then put the path to it in the Custom Preprocessor field in Marked’s Behavior settings.
You’ll need the latest MultiMarkdown binary installed, so grab it if you don’t, and make sure it ends up in /usr/local/bin/multimarkdown
.
Here’s the script:
If you don’t have Marked 2 yet, it has a lot to offer. I’ll be posting more tips and tricks soon!