Skip to content

Commit 27e8d92

Browse files
committed
Feat: Support other languages in template tag handling the content as raw_text
1 parent 91fe275 commit 27e8d92

File tree

7 files changed

+2127
-1670
lines changed

7 files changed

+2127
-1670
lines changed

corpus/spec.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,84 @@ Interpolations - Raw HTML (https://vuejs.org/v2/guide/syntax.html#Raw-HTML)
8585
(end_tag
8686
(tag_name))))
8787

88+
================================================================================
89+
Template: Ignore content if language tag is given
90+
================================================================================
91+
92+
<template lang="pug">
93+
div
94+
| Some {{ inner }} pug here.
95+
| Ignore <HTML /> <tags/> here
96+
</template>
97+
98+
--------------------------------------------------------------------------------
99+
100+
(component
101+
(template_element
102+
(start_tag
103+
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
104+
(raw_text)
105+
(end_tag (tag_name))
106+
)
107+
)
108+
109+
================================================================================
110+
Template: Ignore content if language tag is given, template close is found
111+
================================================================================
112+
113+
<template lang="pug">
114+
.doodle-wrapper
115+
hidden-field-set(:form-name="formName" :values="hiddenAttributes")
116+
simple-page-wrapper(:pages="pages")
117+
118+
</template>
119+
120+
<script lang="ts">
121+
</script>
122+
123+
--------------------------------------------------------------------------------
124+
125+
(component
126+
(template_element
127+
(start_tag
128+
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
129+
(raw_text) (end_tag (tag_name)))
130+
(script_element
131+
(start_tag
132+
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
133+
(raw_text) (end_tag (tag_name)))
134+
)
135+
136+
================================================================================
137+
Template: Not using lang is normal HTML
138+
================================================================================
139+
140+
<template slot="header">
141+
<p>Using mustaches: {{ rawHtml }}</p>
142+
</template>
143+
144+
--------------------------------------------------------------------------------
145+
146+
(component
147+
(template_element
148+
(start_tag
149+
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
150+
(text)
151+
(element
152+
(start_tag
153+
(tag_name))
154+
(text)
155+
(interpolation
156+
(raw_text))
157+
(end_tag
158+
(tag_name)))
159+
(text)
160+
(end_tag (tag_name))
161+
)
162+
)
163+
164+
165+
88166
================================================================================
89167
Interpolations - Attributes (https://vuejs.org/v2/guide/syntax.html#Attributes)
90168
================================================================================

grammar.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ module.exports = grammar({
4949
$.self_closing_tag,
5050
),
5151

52-
template_element: $ => seq(
53-
alias($.template_start_tag, $.start_tag),
54-
repeat($._node),
55-
$.end_tag,
52+
template_element: $ => choice(
53+
seq(
54+
alias($.template_start_tag, $.start_tag),
55+
repeat($._node),
56+
$.end_tag,
57+
),
58+
seq(
59+
alias($.template_start_tag_with_lang, $.start_tag),
60+
optional($.raw_text),
61+
$.end_tag,
62+
),
5663
),
5764

5865
script_element: $ => seq(
@@ -80,6 +87,12 @@ module.exports = grammar({
8087
repeat(choice($.attribute, $.directive_attribute)),
8188
">",
8289
),
90+
template_start_tag_with_lang: $ => seq(
91+
"<",
92+
alias($._template_start_tag_name, $.tag_name),
93+
alias($.lang_attribute, $.attribute),
94+
">",
95+
),
8396

8497
script_start_tag: $ => seq(
8598
"<",
@@ -124,6 +137,16 @@ module.exports = grammar({
124137
),
125138
)),
126139
),
140+
lang_attribute: $ => seq(
141+
alias("lang", $.attribute_name),
142+
optional(seq(
143+
"=",
144+
choice(
145+
$.attribute_value,
146+
$.quoted_attribute_value,
147+
),
148+
)),
149+
),
127150

128151
attribute_name: $ => /[^<>"'=/\s]+/,
129152

src/grammar.json

Lines changed: 127 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)