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

Support for variables in the custom style markup #16

Open tmedwards opened 4 years ago

tmedwards commented 4 years ago

Pretty much what it says on the tin. It would be nice if the custom style markup had some way of supporting variables, if not expressions—similar to what you can currently do with HTML tags and the evaluation attribute directive.

Uzume commented 3 years ago

I assume this is a reference to supporting something like sc-eval in the style-list within scv2 @@ custom style markup, allowing custom styles to be driven by saved story variables and temporary passage/moment variables.

That sounds like a nice feature but it seems like it would need significant syntactic changes and if you are considering such, why not also consider changing the custom style markup to use a different syntax that would allow them to be nested much like how HTML <span> and <div> tags can already be nested. The current style markup (and even markdown; see discussion here) also have nesting issues but at least there it is less important as such style markup is basically fixed to a single style. This is not true for custom styles. Sure one can put numerous things in the provided style-list but due to nesting issues these cannot be provided later (at least not with the same custom style markup). For example, it is currently impossible to specify font styles for something using custom style markup and then provide color styles on something inside that with custom style markup. With the scv2 custom style markup, there is basically there is no way to have the markup emit anything like the following:

<span style="font-family: fantasy">Lorem ipsum dolor sit amet,
<span style="color: red">consectetur adipiscing elit</span>,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</span>

And this cannot be done with the existing scv2 standard/non-custom style markup either. This means any type of advanced styling like this requires the author to resort to inline HTML or create their own custom markup with templates (ug! this might work but would be very error prone at best) or macros (at least here the markup allows abutting to other text easily and there are the concepts of arguments, content and nesting). Using macros seems a tad overkill since any such author custom macros would not need to even consider executing any code like JS API calls or variables of any kind (this is the kind of place I believe an improved template system could be valuable).

Frankly, I find scv2 custom style markup error prone and not highly useful and if I have such styling issues I would rather define my own custom style macros that essentially accomplish the same thing better (and if needed I could easily add sc-eval like variable driven support like this issue is about too).