Skip to content
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

[HTML] Fix scopes of stray script and style tags #3032

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ASP/HTML (ASP).sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ contexts:
- include: script-common
- match: '>'
scope: punctuation.definition.tag.end.html
set:
- script-close-tag
- script-vbscript-content
set: script-vbscript-content

script-vbscript-content:
- meta_include_prototype: false
Expand Down
93 changes: 51 additions & 42 deletions HTML/HTML.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,8 @@ contexts:
###[ HTML TAGS ]##############################################################

tag-html:
- match: (<)((?i:style)){{tag_name_break}}
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
push: style-css
- match: (<)((?i:script)){{tag_name_break}}
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.script.html
push: script-javascript
- include: script-tag
- include: style-tag
- match: (</?)((?i:body|head|html){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
Expand Down Expand Up @@ -184,14 +176,35 @@ contexts:

###[ SCRIPT TAG ]#############################################################

script-tag:
- match: (<)((?i:script)){{tag_name_break}}
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.script.html
push: script-javascript
- match: (</)((?i:script){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.script.html
push: script-close-tag-content

script-close-tag:
- match: (</)((?i:script){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.script.html
set: script-close-tag-content

script-close-tag-content:
- meta_scope: meta.tag.script.end.html
- include: tag-end

script-javascript:
- meta_scope: meta.tag.script.begin.html
- include: script-common
- match: '>'
scope: punctuation.definition.tag.end.html
set:
- script-close-tag
- script-javascript-content
set: script-javascript-content

script-javascript-content:
- meta_include_prototype: false
Expand All @@ -211,12 +224,7 @@ contexts:
script-html:
- meta_scope: meta.tag.script.begin.html
- include: script-common
- match: '>'
scope: punctuation.definition.tag.end.html
set:
- meta_content_scope: text.html.embedded.html
- include: script-close-tag
- include: main
- include: tag-end

script-other:
- meta_scope: meta.tag.script.begin.html
Expand All @@ -225,16 +233,6 @@ contexts:
scope: punctuation.definition.tag.end.html
set: script-close-tag

script-close-tag:
- match: (</)((?i:script){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.script.html
set:
- meta_scope: meta.tag.script.end.html
- include: tag-end
- include: tag-attributes

script-common:
- include: script-type-attribute
- include: tag-attributes
Expand Down Expand Up @@ -287,14 +285,35 @@ contexts:

###[ STYLE TAG ]##############################################################

style-tag:
- match: (<)((?i:style)){{tag_name_break}}
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
push: style-css
- match: (</)((?i:style){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
push: style-close-tag-content

style-close-tag:
- match: (</)((?i:style){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
set: style-close-tag-content

style-close-tag-content:
- meta_scope: meta.tag.style.end.html
- include: tag-end

style-css:
- meta_scope: meta.tag.style.begin.html
- include: style-common
- match: '>'
scope: punctuation.definition.tag.end.html
set:
- style-close-tag
- style-css-content
set: style-css-content

style-css-content:
- meta_include_prototype: false
Expand All @@ -318,16 +337,6 @@ contexts:
scope: punctuation.definition.tag.end.html
set: style-close-tag

style-close-tag:
- match: (</)((?i:style){{tag_name_break}})
captures:
1: punctuation.definition.tag.begin.html
2: entity.name.tag.style.html
set:
- meta_scope: meta.tag.style.end.html
- include: tag-end
- include: tag-attributes

style-common:
- include: style-type-attribute
- include: tag-attributes
Expand Down
27 changes: 19 additions & 8 deletions HTML/syntax_test_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,24 @@
## ^ string.quoted.double.html - text.html.embedded.html
## ^^^^ comment.block.html punctuation
comment -->
## ^^^^^^^^^^^ text.html.embedded.html comment.block.html
## ^^^^^^^^^^^ comment.block.html
<div></div>
## ^^^^^^^^^^^ text.html.basic text.html.embedded meta.tag.block.any
## ^^^^^^^^^^^ text.html.basic meta.tag.block.any
<script type=text/javascript>
## ^ text.html.basic text.html.embedded.html - source.js.embedded.html
## ^ text.html.basic - source.js.embedded.html
function test() {}
## ^ text.html.basic text.html.embedded.html source.js.embedded.html - source.js source.js
## ^ text.html.basic source.js.embedded.html - source.js source.js
</script>
## ^^^^^^^^^ text.html.basic text.html.embedded.html meta.tag.script.end
## ^^^^^^^^^ text.html.basic meta.tag.script.end
</script>
## ^ text.html.basic text.html.embedded.html
## ^^^^^^^^^ text.html.basic - text.html.embedded.html meta.tag.script.end
## ^ text.html.basic - text.html.embedded.html
## ^ text.html.basic - meta.tag
## ^^^^^^^^^ text.html.basic meta.tag.script.end
## ^ text.html.basic - meta.tag

</script>
## ^ text.html.basic - meta.tag
## ^^^^^^^^^ text.html.basic meta.tag.script.end
## ^ text.html.basic - meta.tag

<script>
<!-- i = 0;
Expand Down Expand Up @@ -286,6 +291,12 @@
##^^^^^ meta.tag.style.end.html entity.name.tag.style.html
>
## <- meta.tag.style.end.html punctuation.definition.tag.end.html

</style>
##^^^^^^ meta.tag.style.end.html
##^^^^^ entity.name.tag.style.html
## ^ punctuation.definition.tag.end.html

<style />
## ^ - source.css.embedded.html
## ^ meta.tag.style entity.name.tag.style
Expand Down