-
Notifications
You must be signed in to change notification settings - Fork 597
[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
deathaxe
merged 5 commits into
sublimehq:master
from
deathaxe:pr/html/fix-style-script-toggle-comment
Aug 23, 2021
Merged
[HTML] Fix toggle html comments in css/js tags #2831
deathaxe
merged 5 commits into
sublimehq:master
from
deathaxe:pr/html/fix-style-script-toggle-comment
Aug 23, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
previously approved these changes
May 24, 2021
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.
keith-hall
approved these changes
Aug 22, 2021
jfcherng
approved these changes
Aug 23, 2021
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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