khoulihan / gopher-render

Render HTML and Markdown to plain text or gophermap files.
MIT License
4 stars 0 forks source link

Add CSS selector support for choosing renderers #24

Closed khoulihan closed 4 years ago

khoulihan commented 4 years ago

It would be cool to be able to specify renderers using the syntax of CSS selectors instead of just one renderer type per tag. For example, "li p" would match paragraphs that are children of list items, "div.annotation" would match divs with the class "annotation", and so on. This will help avoid the need for special cases I think, and the internal use of the extension override methods.

Unlike actual CSS, this would have to choose a single best match, rather than cascading the styles, unless I want to rewrite the whole thing to parse CSS or something.

khoulihan commented 4 years ago

This is mostly completed, just a few relevant pseudo-classes to implement and the column combinator.

khoulihan commented 4 years ago

I guess there is a bit of a problem with using this approach actually. If I use this to specify a different paragraph renderer for paragraphs within blockquotes, for example, if a user implements their own paragraph renderer then they need to remember to also apply it to the "blockquote > p" selector with the same settings to ensure proper rendering of paragraphs in that context...

Maybe I should try to implement a sort of cascade, where all matching directives are compared based on their specificity. Specifying a renderer could be optional, and if only settings are specified then overrides occur in order of specificity, while obviously the most specific renderer is used.

khoulihan commented 4 years ago

I added this "cascading" functionality.