I've been messing around trying to get this to work for a while, but for the life of me I can't seem to figure out how to altar the raw text of a passage before it is rendered (to modify links, for instance).
For example, let's say I have this raw text in a passage:
This is my passage text; it is one sentence which contains a [[link|Passage2]] and some text.
Now let's say that before rendering I want to check if the passage that is about to be displayed has a link to Passage2, and change that link to be to Passage3. So before rendering I want to change the above text to:
This is my passage text; it is one sentence which contains a [[link|Passage3]] and some text.
So that the rendered link actually goes to Passage3.
I would think this should be handled via a simple javascript regex replace in a
prerender task function somehow, but I can't seem to replace passage text using a prerender function... only
append text to the passage.
Where/how can I do a simple search/replace of raw passage text before it is rendered?
Thanks!
Comments
Beyond that, I cannot fathom why you'd want to do what you're talking about in the first place. That sort of thing is, literally, why $variables and macros exist. For example: Or:
OK, yes. You could alter the encoded text of a passage within the story data chunk in DOM, but that's… crazy.
Okay, yes, you got me! I guess I was thinking about more general regex text replacement/removal (than would typically be handled by variables), trying to figure out a solution to my typedjs problem, how to remove the caret pauses without breaking the links, thinking I could maybe do that before the links got turned into actual links... but it looks like I've been thinking about the whole "rendering" process all wrong. I'm sure that at least half of what I've been thinking is utterly crazy, and it's good to be told when one's a mad fool, instead of having to simply wonder.
Don't give me any ideas.