Sublime Forum

HTML Comment false highlighting

#1

the following reduces smippet

<!-- "a--c" -->
<!-- a--c -->

produces wrong HTML highlighting
tested using “Marianna” and Build 3156 as well as using the last public one.

0 Likes

#2

HTML 4 does not permit strings of hyphens in comments. This, presumably, is why the syntax definition specifically marks them as invalid.illegal.

However, the HTML 5 spec contains no such prohibition. In light of this, the current behavior should be changed. I’ll see if I can find the time to submit a PR later today.

1 Like

#3

I’ll see if I can find the time to submit a PR

that would be much appreciated, thanks for the quick response anyway!

0 Likes

#4
0 Likes

#5

HTML editing is pretty buggy as a whole

if I:

// 1.
#button:hover{
    width: 300px;
}
#button:hover #button_text_box {
    opacity: 0.8;
}

// 2.
#button:hover{
    /*width: 300px;*/
}
#button:hover #button_text_box {
    opacity: 0.8;
}

// 3.
/*#button:hover{
    /*width: 300px;*/
}
#button:hover #button_text_box {
    opacity: 0.8;
}*/

thus commenting code does not work well at all :expressionless:

0 Likes

#6

That example seems to highlight correctly. You can’t nest comments in CSS; the comment in example 3 properly begins at /*button and ends at 300px;*/. The intervening /* is ignored and the following */ is invalid.

If the objection is that the built-in toggle_comment command produces invalid output in that case, then fair enough, but it’s not clear to me what valid output should be produced. In all of the obvious approaches, running toggle_comment twice would uncomment /*width: 300px*/.

1 Like

#7

If the objection is that the built-in toggle_comment command produces invalid output

yes

is there a way to have the toggle_comment insert // bacause // //stuff would work as a “nested” comment

You can’t nest comments in CSS

does this apply both to both

/*
  /* 
    nested
  */
*/

/// and ///

/*
  // nested
*/

?

0 Likes

#8

there’s no such thing as a // comment in CSS:



https://www.xanthir.com/b4U10

0 Likes

#9

Actually your statement is not totally correct.
Although // is not a standard comment marker in css, you can use whatever unrecognized symbol (you could use even a single comma or a question mark…) to comment, actually let the parser skip, the current line.
So, because // is a single line comment marker in lot of languages, is accepted as a de-facto standard also in css for single line comments.

0 Likes

#10

sorry for the confusion with the // which is as you said probably nonsense.

However the point is:
It would be good if Sublime would detect the enclosed comment, uncomment it and comment the whole selected block instead of producing something that to me looks much like undefined behavior/ gibberish.

0 Likes

#11

The core CSS syntax highlighting does not reflect this because the CSS language does not. It may be that the implementation details of some parsers let you use the invalid syntax // as a sort of pseudo-comment, but if you want to do that you’d be much better off using a CSS extension like Sass that does truly support line comments.

The downside of this approach is that if you ran toggle_comment twice, you would uncomment the inner block. This could result in a user accidentally uncommenting code, which is very dangerous. Whether this is a worse problem than the toggle_comment feature not working well in CSS is a matter of opinion.

0 Likes

#12

fair point however I"d argue that CSS is actually used for styling rather than dangerous things (at least I want to believe this is the case).
Going for the 90% use case of trying to style something seems valid to me.

The current implementation which produces gibberish should at least be changed to not do anything in such a case iMO, but that is not ideal either.

0 Likes