From 6f4b9b190baaa4c10d8e60108ceb61b486f6e1a3 Mon Sep 17 00:00:00 2001 From: Lucario387 Date: Mon, 2 Jan 2023 02:38:54 +0900 Subject: refactor(vue, html): Update injections Update html_tags injections so that html/vue/svelte parsers can use it without having a script/style tag being captured twice Signed-off-by: Pham Huy Hoang --- queries/html/injections.scm | 13 +---- queries/html_tags/injections.scm | 68 ++++++++++++++++++++-- queries/vue/injections.scm | 55 ++++------------- .../injections/html/test-html-injections.html | 45 ++++++++++++++ 4 files changed, 122 insertions(+), 59 deletions(-) create mode 100644 tests/query/injections/html/test-html-injections.html diff --git a/queries/html/injections.scm b/queries/html/injections.scm index 682431195..7ddb5beae 100644 --- a/queries/html/injections.scm +++ b/queries/html/injections.scm @@ -1,12 +1 @@ -((style_element - (raw_text) @css)) - -((attribute - (attribute_name) @_attr - (quoted_attribute_value (attribute_value) @css)) - (#eq? @_attr "style")) - -((script_element - (raw_text) @javascript)) - -(comment) @comment +; inherits html_tags diff --git a/queries/html_tags/injections.scm b/queries/html_tags/injections.scm index 80c0d2a4a..63d00a753 100644 --- a/queries/html_tags/injections.scm +++ b/queries/html_tags/injections.scm @@ -1,7 +1,67 @@ -((style_element - (raw_text) @css)) +; +( + (style_element + (start_tag) @_no_attribute + (raw_text) @css) + (#match? @_no_attribute "^\\<\\s*style\\s*\\>$") + ; unsure why, but without escaping < and > the query breaks +) -((script_element - (raw_text) @javascript)) +; +; Add "lang" to predicate check so that vue/svelte can inherit this +; without having this element being captured twice +( + (style_element + (start_tag + (attribute + (attribute_name) @_no_set_type)) + (raw_text) @css) + (#not-any-of? @_no_set_type "type" "lang") +) + +( + (style_element + (start_tag + (attribute + (attribute_name) @_type + (quoted_attribute_value (attribute_value) @_css))) + (raw_text) @css) + (#eq? @_type "type") + (#eq? @_css "text/css") +) + +; +( + (script_element + (start_tag) @_no_attribute + (raw_text) @javascript) + (#match? @_no_attribute "^\\<\\s*script\\s*\\>$") +) + +; +( + (script_element + (start_tag + (attribute + (attribute_name) @_no_set_type)) + (raw_text) @javascript) + (#not-any-of? @_no_set_type "type" "lang") +) + +( + (script_element + (start_tag + (attribute + (attribute_name) @_type + (quoted_attribute_value (attribute_value) @_javascript))) + (raw_text) @javascript) + (#eq? @_type "type") + (#eq? @_javascript "text/javascript") +) + +((attribute + (attribute_name) @_attr + (quoted_attribute_value (attribute_value) @css)) + (#eq? @_attr "style")) (comment) @comment diff --git a/queries/vue/injections.scm b/queries/vue/injections.scm index 223791c09..84ac2160e 100644 --- a/queries/vue/injections.scm +++ b/queries/vue/injections.scm @@ -1,20 +1,6 @@ -( - (style_element - (start_tag) @_no_attribute - (raw_text) @css) - (#match? @_no_attribute "^\\<\\s*style\\s*\\>$") - ; unsure why, but without escaping < and > the query breaks -) - -( - (style_element - (start_tag - (attribute - (attribute_name) @_no_lang)) - (raw_text) @css) - (#not-eq? @_no_lang "lang") -) +; inherits html_tags +; + + +
+ + Test div to test css injections for style attributes +
+ + -- cgit v1.2.3-70-g09d2