Comment by matt_kantor
3 days ago
> in HTML you have a tree of nodes but comments can be anywhere
Maybe I'm misunderstanding, but no they can't. For example the comment here is not a comment, but part of the URL:
<a href="https://example.com<!-- comment -->">click me</a>
And HTML like this is simply broken:
<div<!-- comment -->>content</div>
Maybe you meant "they can be anywhere that a Node can be in the DOM", but I think that's more or less what the CSS "mistake" is suggesting should be true about CSS (just replace "DOM" with "CSSOM").
Yes, anywhere in the node tree. Imagine if CSS was specified in HTML-style. We might write this selector:
Like this:
Which is pretty much exactly the same as what you'd get as a CST from parsing the CSS.
Problem is, the CSSOM models that more like this:
Perhaps your takeaway from this is "the CSSOM is bad" (and I don't necessarily disagree), but it's what the "mistake" is talking about.
I wouldn't say that, it's more that the CSSOM doesn't try to preserve comments, which is a perfectly reasonable thing to do. I think most uses cases for modifying CSS that care about comments (e.g. auto-formatters?) would need parsers that return the full CST anyway.
3 replies →