From f305abbdf3c8bbcb568cacfb292f38120f388622 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Fri, 10 Sep 2021 01:23:44 +0200 Subject: [PATCH] [HTML] Fix scopes of stray script and style tags (#3032) This commit ... 1. fixes scopes of stray script and style tags, which didn't match those from tag pairs. 2. avoids multi-pushing into embedded script/style syntaxes to simplify the language a bit and improve parsing performance. Closing tags are consumed within `main` context now. 3. removes pushing `text.html.embedded.html` onto stack. a) As `main` context is pushed, it is not required for highlighting. b) The only thing we loose is the mentioned scope, which seems to be of little value. c) It is required as change (2) would break boundaries of `text.html.embedded` otherwise. d) The less contexts HTML pushes onto stack the better it is for most possible flexibility with regards to inheritance or re-use in heavily context aware templating syntaxes such as JSP or PHP. e) It slightly improves parsing performance. 4. New `script-tag` and `style-tag` contexts are introduced to form a kind of template which can be used by inheriting syntaxes for other custom tags. Notes: 1. `script-close-tag` still exists, so existing syntaxes shouldn't break by this change. 2. ASP syntax is adjusted to use the same strategy, but that's just to keep inline. It would have worked without that change, too. --- ASP/HTML (ASP).sublime-syntax | 4 +- HTML/HTML.sublime-syntax | 93 +++++++++++++++++++---------------- HTML/syntax_test_html.html | 27 +++++++--- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/ASP/HTML (ASP).sublime-syntax b/ASP/HTML (ASP).sublime-syntax index 15cc481edee..e8b3e2b5cda 100644 --- a/ASP/HTML (ASP).sublime-syntax +++ b/ASP/HTML (ASP).sublime-syntax @@ -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 diff --git a/HTML/HTML.sublime-syntax b/HTML/HTML.sublime-syntax index 550b68fd492..feb25c1bb99 100644 --- a/HTML/HTML.sublime-syntax +++ b/HTML/HTML.sublime-syntax @@ -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: (' scope: punctuation.definition.tag.end.html - set: - - script-close-tag - - script-javascript-content + set: script-javascript-content script-javascript-content: - meta_include_prototype: false @@ -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 @@ -225,16 +233,6 @@ contexts: scope: punctuation.definition.tag.end.html set: script-close-tag - script-close-tag: - - 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 @@ -318,16 +337,6 @@ contexts: scope: punctuation.definition.tag.end.html set: style-close-tag - style-close-tag: - - match: ( - ## ^^^^^^^^^^^ text.html.embedded.html comment.block.html + ## ^^^^^^^^^^^ comment.block.html
- ## ^^^^^^^^^^^ text.html.basic text.html.embedded meta.tag.block.any + ## ^^^^^^^^^^^ text.html.basic meta.tag.block.any - ## ^^^^^^^^^ text.html.basic text.html.embedded.html meta.tag.script.end + ## ^^^^^^^^^ text.html.basic meta.tag.script.end -## ^ 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 + + +## ^ text.html.basic - meta.tag +## ^^^^^^^^^ text.html.basic meta.tag.script.end +## ^ text.html.basic - meta.tag