logoalt Hacker News

matt_kantorlast Thursday at 5:08 PM1 replyview on HN

> 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").

Replies

IshKebablast Thursday at 6:07 PM

Yes, anywhere in the node tree. Imagine if CSS was specified in HTML-style. We might write this selector:

  h1,
  /* don't forget h2! */
  h2 {
    color: /* I love red */ "red";
  }
Like this:

  <rule>
    <selector>
      <alternative>
         h1
      </alternative> <!-- don't forget h2 -->
      <alternative>
         h2
      </alternative>
    <selector>
    <attributes>
      <color><!-- I love red --> red</color>
    </attributes>
  </rule>
Which is pretty much exactly the same as what you'd get as a CST from parsing the CSS.
show 1 reply