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

nobr affects the content of the <<script>> macro #135

Closed gulumige closed 3 years ago

gulumige commented 3 years ago

Both the nobr passage tag and the <<nobr>> macro removes all line breaks from the content of the <<script>> macro. This can result in valid JS throwing errors as well as invalid JS not throwing errors.

Example of valid JS throwing an error:

:: Example1 [nobr]
<<script>>
  /* regular JS without semicolons*/
  const foo = "Hello, World!"

  temporary().bar = foo
<</script>>

_bar

Removing the nobr tag or adding a semicolon after "Hello, World!" both fixes the issue in this case. (The same would apply if the <<script>> macro was wrapped in a <<nobr>> macro.)

Example of invalid JS not throwing an error:

:: Example2 [nobr]
<<script>>
  /* multiline string, should not work */
  const foo = "Hello;

  World!";

  temporary().bar = foo;
<</script>>

_bar /* no error, output: "Hello; World!" */

Removing the nobr tag throws an appropriate error.

tmedwards commented 3 years ago

That is an unavoidable consequence of how all three of the no-break features work. Anything that depends upon newlines will be affected.

This is, unfortunately, not something that can be addressed in SugarCube v2.