klembot / twinejs

Twine, a tool for telling interactive, nonlinear stories
https://twinery.org
GNU General Public License v3.0
2k stars 295 forks source link

Apply JS/CSS highlighting to passges with script/stylesheet tags #1421

Open hituro opened 1 year ago

hituro commented 1 year ago

Is your feature request related to a problem? Please describe.

Although passages tagged with script or stylesheet have no special implicit meaning in Twine 2, they are nevertheless used by many people to store JS or CSS data (which is then loaded by a compiler, or by a user-script). However, text in those passages is treated as normal passage text, meaning that it gets the passage editor/highlighter when present, and no highlighter at all when not present.

Describe the solution you'd like.

It would be great if those passages were highlighted using the existing JS/CSS highlighting modes.

Describe alternatives you've considered.

An alternative would be to leave this to the StoryFormat to implement in its syntax highlighter, but since many formats don't have one it would be a lot easier if the editor, which already has the appropriate modes, were to handle it.

Additional context on this suggestion.

No response

Presubmission checklist

greyelf commented 1 year ago

which is then loaded by a compiler

A couple of points of clarification:

  1. None of the runtime engines of the main Twine 2.x compatible Story Formats actually do anything special with passages that have been assigned a script or stylesheet tag, and SugarCube 2.x documentation specific notes this fact in its documentation about those tags.
  2. Only the external Twee Notation compilers, like TweeGo, do anything special with such tagged passages and that is at compile time.

So any special handling of such tagged passages in a Twine 2.x compatible Story HTML file must be being done by the Author themselves programmatically, which means that an Author could use any Passage Tag to mark such passages as special.

How will an Author know:

hituro commented 1 year ago

While none of the main StoryFormats currently do anything with those passage tags (though see the feature recently suggested on Sugarcube to provide a mechanism to do such) there is a tradition within Twine development that has given special consideration to such tags, and — as you note — some compilers (TweeGo, Gordian) do specific things with those tags.

SugarCube's Twine 1 mode also treats them as special.

Nevetheless you've hit on the exact reason that I consider this a Twine UI feature, and not a StoryFormat one, the fact that those passages are mostly special outside the context of a particular StoryFormat.

As for why those tags in particular, it's only because they have had special status in the past. Other tags would be perfectly possible.

As would other approaches, such as having user-definable syntax modes on every passage, like an IDE, but that's much more of an ask than this approach.

klembot commented 1 year ago

Not sure how I feel about this idea yet. I don't have a great handle on how many people use these tags and I worry about other variations like "js", "css", "javascript", and so on. There is a localization concern that if we respected the "stylesheet" tag, then we ought to respect all the other translations of "stylesheet", and the same's true for "script".