html5 - Is there a new standard for HTML commenting? -


recently found there is, possibly, new way of commenting in html5.

instead of typical <!-- --> multi-line commenting i've read about, thought noticed ide made regular <!div > commented out. tested out, , surprise chrome had commented out tag. only commented out tag , not contents of div, had comment out closer <!/div> avoid closing other divs.

i tested , appears putting exclamation marker in front of opening of tag, symbol <, makes tag commented out.

is new? bad practice? convenient, practical yet(if not new)?

edit details: although syntax error or misinterpretations of particular syntax reason, how come chrome actually renders them full comments?

the code written as:

<!div displayed> text here still displayed <!/div> 

and rendered as:

<!--div displayed--> text here still displayed <!--/div--> 

there no new standard comments in html5. valid comment syntax still <!-- -->. section 8.1.6 of w3c html5:

comments must start 4 character sequence u+003c less-than sign, u+0021 exclamation mark, u+002d hyphen-minus, u+002d hyphen-minus (<!--).

the <! syntax originates in sgml dtd markup, not part of html5. in html5, reserved comments, cdata sections, , doctype declaration. therefore whether alternative bad practice depends on whether consider use of (or worse, dependence on) obsolete markup bad practice.

validator.nu calls have "bogus comment." — means it's treated comment though it's not valid comment. presumably backward compatibility pre-html5, sgml-based, , had markup declarations took form <!foo>, wouldn't call new. reason they're treated like comments because sgml markup declarations special declarations not meant rendered, since meaningless in html5 (with above exceptions), far html5 dom concerned are nothing more comments.

the following steps within section 8.2.4 lead conclusion, chrome appears following letter:

  1. 8.2.4.1 data state:

    consume next input character:

    "<" (u+003c)
    switch tag open state.

  2. 8.2.4.8 tag open state:

    consume next input character:

    "!" (u+0021)
    switch markup declaration open state.

  3. 8.2.4.45 markup declaration open state:

    if next 2 characters both "-" (u+002d) characters, consume 2 characters, create comment token data empty string, , switch comment start state.

    otherwise, if next 7 characters ascii case-insensitive match word "doctype", consume characters , switch doctype state.

    otherwise, if there adjusted current node , not element in html namespace , next 7 characters case-sensitive match string "[cdata[" (the 5 uppercase letters "cdata" u+005b left square bracket character before , after), consume characters , switch cdata section state.

    otherwise, parse error. switch bogus comment state. next character consumed, if any, first character in comment.

    notice says switch comment start state if sequence of characters encountered <!--, otherwise it's bogus comment. reflects stated in section 8.1.6 above.

  4. 8.2.4.44 bogus comment state:

    consume every character , including first ">" (u+003e) character or end of file (eof), whichever comes first. emit comment token data concatenation of characters starting , including character caused state machine switch bogus comment state, , including character before last consumed character (i.e. character before u+003e or eof character), u+0000 null characters replaced u+fffd replacement character characters. (if comment started end of file (eof), token empty. similarly, token empty if generated string "<!>".)

    in plain english, turns <!div displayed> <!--div displayed--> , <!/div> <!--/div-->, described in question.

on final note, can expect other html5-compliant parsers behave same chrome.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -