videlais / snowman

An advanced Twine 2 story format designed for people who already know JavaScript and CSS
MIT License
128 stars 35 forks source link

Paragraph tags misplaced for first paragraph in Windows #186

Open mcdemarco opened 4 years ago

mcdemarco commented 4 years ago

If you create a new story in Windows using the latest Twine (2.39) and Snowman (2.0.2), the first paragraph in every passage will be missing its paragraph tags, which appear to be shifted onto the next line as an empty paragraph tag. While this has no obvious visual effect out of the box (you have to view the rendered source of the passage to see it), it will mess up any paragraph-based CSS or scripting.

This does not happen on (unix-based) MacOS X. It seems to be a result of some paragraph cleanup code at the end of Passage.js aimed at fixing marked output. The code assumes unix newlines (\n) instead of windows newlines (\r\n). There are other cases as well, like classic mac newlines (\r), but Twine users are unlikely to run into them.

Note that importing a story into a Windows Twine can preserve unix newlines, and then the problem won't occur. (It's not clear exactly what the import and Twine are doing, but for a story I imported the newlines remained unix-style even after some editing in Windows.)

As a temporary workaround I suggested converting the published story to unix newlines, but the original reporter (bphennessy on discord) went with a jQuery fix instead:

var firstpar = $(".passage").contents().filter(function(){ 
  return this.nodeType == 3; 
})[0]

$(firstpar).wrap("<p></p>")

To fix Snowman itself I assume a better regex would be sufficient, depending on what problem the code was fixing:

    if ((!result.endsWith('</p>\n') && newResult.endsWith('</p>\n')) || (!result.endsWith('</p>\r\n') && newResult.endsWith('</p>\r\n')) {
      newResult = newResult.replace(/^<p>|<\/p>$|<\/p>(\r)?\n$/g, '');
    }

Since I can't reproduce the original issue (my stories behave the same with and without the paragraph correction code) I can't be sure that actually works as intended.

videlais commented 2 years ago

Thanks for reporting this. It is an issue with Marked I'd been fighting with for a long time. The newest build should fix it by no longer generating paragraph tags (and removing Marked from the project).

sheridanvk commented 9 months ago

Would you mind clarifying which build this is fixed in (and providing the URL for it so I can add it to Twine)? I have this issue with Snowman 2.0.2, and it's not clear to me if you're saying this is fixed in v3 (which I believe is not production-ready yet?) or some other version?

thank you!

videlais commented 9 months ago

Hi, @sheridanvk. The issue was fixed in the work toward Snowman 3.X. There have been no updates to Snowman 2.X since Summer 2022.

sheridanvk commented 9 months ago

Thanks for the fast reply! Is there a format link where I can try out 3.x?

videlais commented 9 months ago

Is there a format link where I can try out 3.x?

You can try this link or otherwise download the last format.js build from the latest experimental build from August 2023. However, this comes with a MAJOR caveat. I make absolutely no guarantee it will work. Snowman 3.X is very different than the Snowman 2.X branch.

I'll re-open this issue for now for the 2.X branch, but I do not know when I can address it.