Sublime Forum

Toggle_comment inconsistant syntax comment for scope in HTML file

#1

Description

The command toggle_comment creates different comment syntax for the scopes CSS or JS.

For example, in a HTML document, inside a CSS scope or JS scope, use toggle comment to place a comment. This will place a HTML comment inside CSS scope. All consecutive comments are for correct syntax inside this scope.

I learned that this is technically correct:

when using the <style> element, you may use <!-- --> to hide CSS from older browsers, although this is not recommended.

source: https://developer.mozilla.org/en-US/docs/Web/CSS/Comments

However, it is inconsistent and annoying me. I am not sure if this is intended, what is the point in using two different syntax for the same command?

Steps to reproduce

  1. create HTML document as PHP file
  2. inside HTML document, create CSS or JS script
  3. inside CSS scope, toggle_comment
  4. add another comment
  5. observe 1st comment in HTML syntax

Actual behavior

1st comment inside CSS scope is in HTML syntax, consecutive comments inside the same scope is in CSS syntax.

st3_toggle_comment

Does it make sense to suggest an improvement here? Meaning that the type of comment applied being consistent within the current scope.

0 Likes

#2

it looks like this is due to the way the embedded language’s syntax isn’t applied until some non-whitespace appears.
I think there was a reason why it was done this way, though this consequence wasn’t foreseen. I think it’s worth logging an issue at https://github.com/sublimehq/Packages/issues for it

1 Like

#3

https://github.com/sublimehq/Packages/issues/2321

done.

0 Likes

#4

Looks like something went wrong. The issue does not exist. (made a new one https://github.com/sublimehq/Packages/issues/2322)

That said I am a little bit uncertain about that issue with a look into HTML.sublime-syntax as it contains support for some legacy xml comments within script/style tags.

Example

<html>
<head>
<script> <!-- ... some java code ... --></script>
<style> <!-- ... p { color: red; } ... --></style>

In the far far past scripts needed to be commented out, maybe styles, too - don’t remember. The HTML.sublime-syntax therefore propably intends to support quickly adding a xml style comment directly after the tag name.

While the comments are highlighted as such in scripts, they are not in CSS.

If somebody could confirm we don’t need xml comments to mask CSS rules, the issue could easily be fixed by starting the source.css scope directly after the opening style tag instead of the next nonewhitespace character.

0 Likes

#6

yes, styles have had been commented out as well, using the format <!--[if !IE]> for cross browser support, for example.

0 Likes