tmedwards / tweego

Tweego is a free (gratis and libre) command line compiler for Twine/Twee story formats, written in Go.
https://www.motoslave.net/tweego
BSD 2-Clause "Simplified" License
124 stars 23 forks source link

Error compiling twee file with CSS pseudo-elements #11

Closed Enolabutterfly closed 4 years ago

Enolabutterfly commented 4 years ago

There is the simple test html file in this zip archive. With CSS pseudo-elements ::placeholder and ::first-line 1.zip

How to create error: Firstly, I decompiled "1.html" to "1.twee", after I tried to compile "2.html" from "1.twee". But then compiler wrote something like that: "error: load 1.twee: line 16: Malformed twee source; unterminated metadata block."

There are many pseudo-elements, which might not compiled properly. Because of syntax. MDN web docs Pseudo-elements

tmedwards commented 4 years ago

Attempting to use syntax that is indistinguishable from the Twee notation passage declaration syntax is never going to work in any Twee compiler.

The easy solution is to ensure that your CSS rules do not look like passage declarations to the compiler—i.e., do not have double-colon-prefixed selectors start the line.

Not specifying a target element for any simple sub-selector implicitly uses the universal selector (*). Thus, in the case of attempting to apply a pseudo-selector globally to all elements, where there would be confusion with Twee passage declarations, simply use an explicit universal selector. For example:

*::first-line {
    /* style properties… */
}
*::placeholder {
    /* style properties… */
}

That said. I recommend being specific when you can, otherwise you're likely to target more elements than you intended.

Case in point. The ::first-line pseudo-element affects block-level elements, so by attempting to apply it to all elements you're likely to target elements you do not want. Rather, you should be explicit and target only the elements you need. For example, to target paragraphs:

p::first-line {
    /* style properties… */
}

The ::placeholder pseudo-element affects only specific elements to begin with, so it's safer to use with the universal selector—either implicitly or explicitly. Though, being specific with it wouldn't hurt either. For example:

input::placeholder {
    /* style properties… */
}