←back to thread

197 points OuterVale | 2 comments | | HN request time: 0.499s | source
Show context
yread ◴[] No.46229304[source]
I don't understand the point about comments. Why shouldn't they be allowed? What object model?

>Comments shouldn't have been allowed basically everywhere in CSS (compare to HTML, which basically only allows them where content goes), because it makes them basically unrepresentable in the object model, which in turn makes building editing directly on top of the object model impossible

replies(5): >>46229365 #>>46229381 #>>46229430 #>>46229509 #>>46231920 #
systoll ◴[] No.46229509[source]
The CSS Object Model.

HTML comments are basically just a HTML tag that isn't rendered. Tools that 'compile' the HTML code into a document tree, including browsers, preserve comments as nodes without any extra effort.

CSS comments can go anywhere:

    /*wow*/ .selector /*x*/ {animation /*z*/: 2s /*z*/ linear /*z*/ bounce;}
Tools that transform/parse CSS can either: 1. Strip comments before parsing, meaning anything based on the parsed version will lose the comments. 2. Dedicate a disproportionate amount of complexity to retaining the comments, and still not really have a good way to handle them through edits/transformations.
replies(1): >>46229654 #
1. yread ◴[] No.46229654[source]
But if it's valid CSS it has to be representable in AST/object model? It's a comment, it can't have any child nodes, it doesn't depend on anything - pretty trivial. And if it's in the tree you can transform it with proper tools. If you are transforming CSS you have to write a proper parser and not just a bunch of regexes

EDIT: also why is it useful to have comments in the object model in the first place? To access them from js?

replies(1): >>46230205 #
2. nialse ◴[] No.46230205[source]
Round-tripping to CSS and keeping information that may be useful to the user if they would inspect the content I would presume.

A similar issue is CDATA in XML which is not retained when round-tripped. Very annoying, but in line with the spec.