Stylesheets icon indicating copy to clipboard operation
Stylesheets copied to clipboard

Need to consider implementing support for rendition/@selector

Open martindholmes opened this issue 10 years ago • 3 comments

I say "consider implementing" because it's by no means easy.

@selector, which will be in the next P5 release, allows the use of CSS selectors to link rendition elements to elements in the text of the document. It reverses the normal direction of such linking (pointing from element up to rendition in the header using @rendition), and allows default styles to be associated with groups of elements in the CSS manner.

We need to decide whether it's worth trying to support this in the Stylesheets (in rendering to HTML, in particular, but presumably also other end-user output formats). It will not be easy; the CSS selectors will have to be parsed, presumably in a pre-flight pass over the document, and converted into links going the other way using @rendition.

The first issue is parsing CSS selectors with XPath. We might look at other projects such as this python implementation of a CSS parser:

http://svn.colorstudy.com/home/ianb/css2xpath/cssselect.py

for ideas; we might also be able to take advantage of the xsl:evaluate element in XSLT 3.0 to apply the results to retrieve a nodelist.

Another option is simply to say "this is too hard [for the moment]."

martindholmes avatar Jun 25 '15 18:06 martindholmes

we seem to have one step forward and two back, by adding a notation we don't know how to parse. if we can't implement it here, why add it at all?

parsing selector="text, front, back, body, div, p, ab" would not be that hard, so one strategy is partial implementation. but is that going to be sufficient? the example in the spec of <rendition scheme="css" selector="*[rend*=italic]"> font-style: italic;</rendition> strikes me as simply absurd, especially as its potentially circular. why would we encourage people to use @rend and ???

the pre-flight strategy of annotating every element with @rendition would work, albeit at the cost of verbosity. although you can't be sure when it fires. if, for example, <head> is said to be italic, does that also apply when in TOC mode? ` shall I mention namespaces?

sebastianrahtz avatar Jun 26 '15 10:06 sebastianrahtz

Remember the purpose of P5 is not to feed directly into rendering; people are using this to record the original appearance of their source text. There's no requirement that anything be rendered in any particular way. We don't have to see everything through the lens of the Stylesheets.

I'll be using it in projects -- it'll save a huge amount of redundancy -- and if it's not practical for the Stylesheets to support it, and I'll write my own support for it there.

HTML custom elements will let us use this almost directly, though, without parsing, so I think it'll come into its own eventually.

Cheers, Martin

On 2015-06-26 08:38 PM, Sebastian Rahtz wrote:

we seem to have one step forward and two back, by adding a notation we don't know how to parse. if we can't implement it here, why add it at all?

parsing selector="text, front, back, body, div, p, ab" would not be that hard, so one strategy is partial implementation. but is that going to be sufficient? the example in the spec of | font-style: italic;| strikes me as simply absurd, especially as its potentially circular. why would we encourage people to use @rend https://github.com/rend /and/ ???

the pre-flight strategy of annotating every element with @rendition https://github.com/rendition would work, albeit at the cost of verbosity. although you can't be sure when it fires. if, for example, |

| is said to be italic, does that also apply when in TOC mode? ` shall I mention namespaces?

— Reply to this email directly or view it on GitHub https://github.com/TEIC/Stylesheets/issues/112#issuecomment-115637667.

martindholmes avatar Jun 27 '15 00:06 martindholmes

@ebeshero and I believe that this will be plausible if/when there is a good XPath parser for CSS selectors, which is not a huge ask, and will probably appear at some point. The ticket should be parked until then,

martindholmes avatar May 26 '20 14:05 martindholmes