Is there any simple way to pipe note text through some bash script before it’s rendered in the preview?
I have notes that include a lot of mathematics and diagrams, so I have various Pandoc scripts and filters that expand macros out into standard Mathjax-compatible commands, convert tex environments to divs, replace tikzcd diagrams with SVG, etc. As a result, the default Obsidian preview isn’t pretty, since the Mathjax config isn’t easily exposed, the Mathjax plugin has limited macro functionality, and even then it’s rendering the “untransformed” version of the note. Any ideas?
(Note: I am currently working around this by just opening the note externally in vim and doing transformation commands and previews there, it’s just a bit clunky.)
Is this a current feature? In either case, I’m not sure it would quite work: this is mostly about what’s displayed in the preview. And for tex/mathematics, one doesn’t usually want to alter the “source” file, e.g. by replacing diagram code with an image in the original file, but rather have it rendered in previews (and on the fly when it’s later compiled).
This could very well work, if there’s some way to intercept the text before it’s rendered in the preview. If this is doable, are there plugins that do anything like this? Or is there any documentation for how this might be done?
I could see how, in theory, it would be possible for either a plugin to provide an alternative renderer for files with a certain extension, or for it to permit an intermediate stage between markdown and the final renderer in which some preprocessing was done.
At the moment, I think all you could do is to save the files you want processed with a different extension, set up a file listener for such files being modified, and then process them to markdown files. Of course, this has the disbenefit of having to jump from the source to the processed file to preview but I can’t see a way round at the moment.
Hmm so I think this suggestion is probably more complex than what I’m currently doing (setting a separate default program for .md files and rendering there). And the type of markdown pre/postprocessing is already partially in the plugin API, e.g. see the injection of some extra HTML elements in the preview here:
The main stumbling block for doing this in a plugin is that the markdown postprocessor seems to operate on HTML/DOM directly, after the raw note text has been piped through some internal markdown->HTML conversion. What I’d need is a hook before the markdown is converted, or maybe even just the ability to override that conversion step entirely in a plugin and generate my own HTML to pass along to the preview.