I like my text to read smoothly. Sometimes, the way a given sentence starts may depend on how the previous sentence ended.
If I use <<linkreplace>> (a very handy tool!) to let the reader read some additional narrative if desired, I will sometimes need the following sentence (the one after the linkreplace content) to vary, depending on whether or not the linkreplace text was displayed. This is difficult to achieve.
One way to do it is to drop the start of the following sentence, containing all of the material that needs to vary, into the linkreplace. But in this case the start of the following sentence will be highlighted as part of the link. This is both ugly and inappropriate. So I tried the following (which doesn’t work):
<<set _done to false>>\
Testing: <<linkreplace "This text" t8n>>This text <<set _done to true>>has its own sentence ending.<</linkreplace>> <<if _done is false>>still needs a sentence ending.<</if>>
It doesn’t work, I believe, because the material outside the linkreplace has already been rendered. That is, the variable _done has been evaluated early. The value is changed inside the linkreplace, but that doesn’t matter, because the text after the linkreplace has already been set up by the browser and is not being revised.
Is there a way to force the browser to re-evaluate an already rendered textblock and then reprint it after the new value of a variable has been set?
It doesn’t work, I believe, because the material outside the linkreplace has already been rendered. That is, the variable _done has been evaluated early. The value is changed inside the linkreplace, […]
That’s not what’s happening. The stuff inside <<link>> and <<linkreplace>> is only run once the link is clicked (and run fresh every time you click it). It’s not like <<set>> or <<script>> that are run immediately.
[…] but that doesn’t matter, because the text after the linkreplace has already been set up by the browser and is not being revised.
That’s correct. But it’s not being revised because it’s outside of the scope of the <<linkreplace>>.
<<linkreplace>> is for replacing only what’s in the quoted argument with what’s between the tags. If you want to replace something that’s not included in the argument, then you’ll need to give it an ID and pass it to <<replace>>. Your situation makes <<link>> a better tool for the job.
Testing: <<link "This text">><<if !_done>><<set _done = true>><<replace "#trailing" t8n>> has its own<</replace>><</if>><</link>><span id="trailing"> still needs a</span> sentence ending.
Additionally, you can wrap the whole thing in the span and then the link will be replaced, making it a one-time thing. This has the added benefit of it not needing a variable or if statement.
Testing: <span id="replace-me"><<link "This text">><<replace "#replace-me" t8n>>This link has its own<</replace>><</link>> still needs a</span> sentence ending.