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
185 stars 42 forks source link

<<cycle>> links display wrong when changed if Config.cleanupWikifierOutput is enabled #154

Open HiEv opened 3 years ago

HiEv commented 3 years ago

Describe the bug. When using the <<cycle>> macro with Config.cleanupWikifierOutput enabled, cycle links are changed to paragraphs once you click on them.

To Reproduce: Put the following in your JavaScript section:

Config.cleanupWikifierOutput = true;

and this into a passage:

You <<cycle "_ccmodifier">>
    <<option "stuff" -10>>
    <<option "carefully place" 10>>
<</cycle>> the paper into your bag.

Once you then click on that link it goes from being displayed like this:

You _stuff_ the paper into your bag.

to this:

You 

_carefully place_

the paper into your bag.

Looking at the HTML, the link gets wrapped in a <p> (paragraph) element.

Expected behavior: Clicking the <<cycle>> link while Config.cleanupWikifierOutput shouldn't cause the link to become a paragraph.

Project details:

HiEv commented 3 years ago

Here's a workaround until this is fixed (goes in the JavaScript section):

$(document).on(":passagerender", function (event) {
    var clinks = $(event.content).find(".macro-cycle");
    if (clinks.length) {
        clinks.on("click", function () {
            $(this).find("p").contents().unwrap();
        });
    }
});