Closed jshank closed 1 year ago
You could write a complex regexp expression, or you could nest multiple helpers like:
{{replacereg (replacereg field1 regexp1 replace1) regexp2 replace2}}
At any time you should be able to use (...) instead of a single parameter to one of these helper functions.
Great! That solves the problem. Is there any way I can document that replacereg as a helper and call it from multiple places in the template or do I have to make a copy for each call?
I'm not an expert on handlebars, but I don't think that it is possible to set variables, so you will have to copy the expression each time.
Version 0.22.0 is just being released right now. It provides an additional helper function which might help you: {{setvar varName varValue}}
In the simplest case, varName will be a string wrapped in quotes and varValue would be an expression.
That will definitely help. I was looking to see if the current implementation supported block-helpers:
Something like this:
Handlebars.registerHelper('parse5eTools', function(text) {
text = text.replace('/\{@(?:condition|spell|creature|class|race|skill|action|sense) (.+?)\}/g', '[[$1]]');
text = text.replace('/\{@(?:dice) (.+?)\}/g', '`dice: $1` ($1)');
text = text.replace('/\{@(?:filter|item) (.+?)\|.+?\}/g', '$1');
return text;
});
I could then call {{{parse5eTools text}}}
for each block that needs to decode text.
https://handlebarsjs.com/guide/block-helpers.html
I've already added the helpers that are described in the readme.
I'm sure there's a way for me to export the handlebars variable for other modules/add-ons to add their own helpers too. It would just require adding some sort of synchronisation to the obsidian modules.
(I don't really know how modules work in Obsidian - most of my work have been in writing modules for Foundry VTT.)
With the new setvar function, you should be able to save the regexp expressions for later usage; so that you're not having to copy very long regexp strings for each usage.
Is there a way to run multiple replacereg on the same item? I'm capturing a large body of text and need to replace a few items inside of it.