I would like to run a regex replace when tiddlers are rendered. Is there some sort of hook that would allow me to do this?
In my case I want to adjust the content of my tiddler to replace plain-text fractions with more attractive versions so that
3/4 cup sugar
becomes
<sup>3</sup>⁄<sub>4</sub> cup sugar
which will render as
3⁄4 cup sugar
The JS to do this is trivial:
const handleFractions = (s) =>
s.replace(/\b(\d+)\/(\d+)\b/g, `<sup>$1</sup>⁄<sub>$2</sub>`)
and I’m sure converting that to a wikitext version would be simple. But how do I hook it into the rendering routine?
I see Hook: th-rendering-element, which looks vaguely related, but I think what I’m looking for would have to be earlier in the rendering cycle, as I’m looking for something that converts wikitext to wikitext+HTML, before any DOM parse nodes would have been created.
I don’t know if I would want to apply this to all tiddler or just those that match a particular fitler (like perhaps [tag[Recipe]].)
I know I could easily add a macro
/procedure
to render, say <<frac 3 4>> cup sugar
, but I want the text entry to be as simple as possible for users.
Is this easy to do now? Is it possible?