tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

Config.cleanupWikifierOutput = true injects extra <p> blocks in delayed-output macros #61

Closed Akjosch closed 2 months ago

Akjosch commented 4 years ago

The issue was discovered (not by me) in a simple text where part of it was added later using the <<timed>> macro. Boiling it down to the smallest possible code, the following code creates markedly different results depending on the Config.cleanupWikifierOutput setting:

<<nobr>>Text <<timed 1s>>more text<</timed>>.<</nobr>>

Result with Config.cleanupWikifierOutput = false

Text <span class="macro-timed">more text</span>.

Result with Config.cleanupWikifierOutput = true

Text <span class="macro-timed"><p>more text</p></span>.

Inside of the <<timed>> macro specifically, the Wikifier gets called without any options:

new Wikifier(frag, item.content);

Ref: https://github.com/tmedwards/sugarcube-2/blob/master/src/macros/macrolib.js#L3426

... but even if it was, there is currently no option to not surround the result with a <p>...</p> block that would be passed on to the internal convertBreaks() method. The issue is compounded by the fact that a construct like this:

A starting paragraph <<timed 1s>>that is being extended...

And also split apart<</timed>>. Isn't it //fun//?!?

... would require the macro to split the surrounding <p> DOM element into two ore more.


No generically applicable workaround aside of not using the setting exist yet, to my knowledge. For the use case of "inline" <<timed>> only, the following as a replacement of the above line of the <<timed>> macro works well enough:

let oldCleanup = Config.cleanupWikifierOutput;
Config.cleanupWikifierOutput = false;
new Wikifier(frag, item.content);
Config.cleanupWikifierOutput = oldCleanup;
tmedwards commented 4 years ago

Yes. This is a thorny problem for multiple reasons. This may need to be pushed to v3.