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

Investigate API to hook into user scripts loading #242

Open tmedwards opened 1 year ago

tmedwards commented 1 year ago

Investigate adding an API to allow hooking into the user scripts load sequence to allow custom special tags with associated behaviors.

E.g.,

_CustomTagAPI_.add('userscript', function (passage) {
    /* Process `passage` as a script. */
});
_CustomTagAPI_.add('userstyle', function (passage) {
    /* Process `passage` as a stylesheet. */
});
_CustomTagAPI_.add('something', function (passage) {
    /* Process `passage` in some way. */
});

This can already be done with JavaScript alone, so this isn't a necessity, but it might be nice to have.

hituro commented 1 year ago

It would likely be cleaner than the various JS solutions if only because there are nuances to the processing of special elements (e.g. the IMG markup in stylesheets) that could otherwise be left out.