Skip to content

[HTML] Fix toggle html comments in css/js tags #2831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

deathaxe
Copy link
Collaborator

@deathaxe deathaxe commented May 24, 2021

Fixes #2322
Fixes sublimehq/sublime_text#4701

In order to enable comment toggling using rules of embedded syntax definitions it is important to maintain its main scope at the beginning of first and last line.

The challenge is to also support CSS/JS being wrapped into HTML comment markers.

Another goal is to keep as many implementation details away from contexts which may need to be overridden by inheriting syntax definitions such as ASP/JSP/PHP to keep dependencies low. Some little changes are required though at this point to accomplish that.

Note: This commit includes the assumption that JavaScript won't contain a standalone --> on a single line.

Also note this PR may have infuence on implementation details in #2654, #2789 and #2797

Fixes sublimehq#2322

In order to enable comment toggling using rules of embedded syntax
definitions it is important to maintain its main scope at the beginning
of first and last line.

The challenge is to also support CSS/JS being wrapped into HTML
comment markers.

Another goal is to keep as many implementation details away from
contexts which may need to be overridden by inheriting syntax
definitions such as ASP/JSP/PHP to keep dependencies low. Some little
changes are required though at this point to accomplish that.

Note: This commit includes the assumption that JavaScript won't contain
      a standalone `-->` on a single line.
FichteFoll
FichteFoll previously approved these changes May 24, 2021
deathaxe added 2 commits May 25, 2021 17:17
Fixes #sublimehq/sublime_text/issues/4701

This commit introduces a change to ensure the very first char of the
very first line after a <script> or <style> tag to receive correct
source.js vs. source.css scope in case not html comment is present.

As a result toggling comments gives JS/CSS comments precedence over HTML
comments, while maintaining highlighting of existing HTML comments.

As latter one are present for backward compatibility with no longer supported browsers of the 90s, it is assumed wrapping JS/CSS into HTML
comments is no longer a common task and thus entering those comments
manually is acceptable once they are needed.

Before this commit hitting `ctrl+/` at

```
<script>
  |
</script>
```

resulted in

```
<script>
  <!-- | -->
</script>
```

Now it results in

```
<script>
  // |
</script>
```

Same for `<style>`.
This commit removes one level of abstraction.

The removed separation between  `...-begin` and `...-content` context
turned out to be useless with regards to avoid dependencies between
inherited and inheriting syntax definition.

It's because the inheriting syntax needs to handle those HTML comments
in front of closing tags by itself anyway. So it can do the same for
the opening comment and we can save one useless context switch.

Learned from adding VBScript highlighting in script tags of ASP syntax.
This comment:

1. directly captures closing html comment punctuation and remaining
   source scopes via escape_captures.

   It avoids `javascript-end` and `style-end` contexts, which used to
   consume those before.

   It avoids inheriting syntaxes to need to struggle with closing tag
   contexts. Once tag names are a bit more generic, we may even drop
   the `script-close-tag` and `style-close-tag` contexts.

2. adds some descriptions and justifications to the patterns used to
   embed and escape from JS/CSS content.

3. refines some test cases.

As a result, an inheriting syntax definition just needs to implement one
context to override existing JS/CSS contexts.
@deathaxe deathaxe merged commit 2d7ce45 into sublimehq:master Aug 23, 2021
@deathaxe deathaxe deleted the pr/html/fix-style-script-toggle-comment branch August 23, 2021 15:04
mitranim pushed a commit to mitranim/Packages that referenced this pull request Mar 25, 2022
* [HTML] Fix toggle html comments in css/js tags

Fixes sublimehq#2322

In order to enable comment toggling using rules of embedded syntax
definitions it is important to maintain its main scope at the beginning
of first and last line.

The challenge is to also support CSS/JS being wrapped into HTML
comment markers.

Another goal is to keep as many implementation details away from
contexts which may need to be overridden by inheriting syntax
definitions such as ASP/JSP/PHP to keep dependencies low. Some little
changes are required though at this point to accomplish that.

Note: This commit includes the assumption that JavaScript won't contain
      a standalone `-->` on a single line.

* [HTML] Fix toggle comments on first line of script/style content

Fixes #sublimehq/sublime_text/issues/4701

This commit introduces a change to ensure the very first char of the
very first line after a <script> or <style> tag to receive correct
source.js vs. source.css scope in case not html comment is present.

As a result toggling comments gives JS/CSS comments precedence over HTML
comments, while maintaining highlighting of existing HTML comments.

As latter one are present for backward compatibility with no longer supported
browsers of the 90s, it is assumed wrapping JS/CSS into HTML comments is no
longer a common task and thus entering those comments manually
is acceptable once they are needed.

Before this commit hitting `ctrl+/` at

```
<script>
  |
</script>
```

resulted in

```
<script>
  <!-- | -->
</script>
```

Now it results in

```
<script>
  // |
</script>
```

Same for `<style>`.

* [HTML] Simplify CSS/JS embedding

This commit removes one level of abstraction.

The removed separation between  `...-begin` and `...-content` context
turned out to be useless with regards to avoid dependencies between
inherited and inheriting syntax definition.

It's because the inheriting syntax needs to handle those HTML comments
in front of closing tags by itself anyway. So it can do the same for
the opening comment and we can save one useless context switch.

Learned from adding VBScript highlighting in script tags of ASP syntax.

* [HTML] Refine script and style embedding

This comment:

1. directly captures closing html comment punctuation and remaining
   source scopes via escape_captures.

   It avoids `javascript-end` and `style-end` contexts, which used to
   consume those before.

   It avoids inheriting syntaxes to need to struggle with closing tag
   contexts. Once tag names are a bit more generic, we may even drop
   the `script-close-tag` and `style-close-tag` contexts.

2. adds some descriptions and justifications to the patterns used to
   embed and escape from JS/CSS content.

3. refines some test cases.

As a result, an inheriting syntax definition just needs to implement one
context to override existing JS/CSS contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

javascript comments get confused [HTML] toggle_comment toggles html comment within CSS blocks
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy