twinejs icon indicating copy to clipboard operation
twinejs copied to clipboard

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

Open hituro opened this issue 2 years ago • 3 comments

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

  • [ ] I am interested in working on code that would implement this feature request. (This is not required to submit a suggestion.)
  • [X] I have done a search and believe that an issue does not already exist for this idea in the GitHub repository.
  • [X] I have read and agree to abide by this project's Code of Conduct.

hituro avatar Jul 10 '23 23:07 hituro

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:

  • to assigned a script or stylesheet tag to a Passage to mark it as being JavaScript or CSS code related instead of TwineScript based? And why use the script or stylesheet tags to indicate code type, instead of javascript and css?
  • what, potentially Story Format specific, additional JavaScript code they will need to use to convert the contents of those specially marked passages into actual JavaScript and CSS usable by the generated Story HTML file. eg. does this new feature also require the documentation of the Story Formats to also be updated.

greyelf avatar Jul 11 '23 12:07 greyelf

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.

hituro avatar Jul 11 '23 13:07 hituro

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".

klembot avatar Jul 20 '23 03:07 klembot