Skip to content

Commit

Permalink
Feat: Support other languages in template tag handling the content as…
Browse files Browse the repository at this point in the history
… raw_text
  • Loading branch information
zealot128 committed Jan 6, 2022
1 parent 91fe275 commit 27e8d92
Show file tree
Hide file tree
Showing 7 changed files with 2,127 additions and 1,670 deletions.
78 changes: 78 additions & 0 deletions corpus/spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,84 @@ Interpolations - Raw HTML (https://vuejs.org/v2/guide/syntax.html#Raw-HTML)
(end_tag
(tag_name))))

================================================================================
Template: Ignore content if language tag is given
================================================================================

<template lang="pug">
div
| Some {{ inner }} pug here.
| Ignore <HTML /> <tags/> here
</template>

--------------------------------------------------------------------------------

(component
(template_element
(start_tag
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
(raw_text)
(end_tag (tag_name))
)
)

================================================================================
Template: Ignore content if language tag is given, template close is found
================================================================================

<template lang="pug">
.doodle-wrapper
hidden-field-set(:form-name="formName" :values="hiddenAttributes")
simple-page-wrapper(:pages="pages")

</template>

<script lang="ts">
</script>

--------------------------------------------------------------------------------

(component
(template_element
(start_tag
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
(raw_text) (end_tag (tag_name)))
(script_element
(start_tag
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
(raw_text) (end_tag (tag_name)))
)

================================================================================
Template: Not using lang is normal HTML
================================================================================

<template slot="header">
<p>Using mustaches: {{ rawHtml }}</p>
</template>

--------------------------------------------------------------------------------

(component
(template_element
(start_tag
(tag_name) (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
(text)
(element
(start_tag
(tag_name))
(text)
(interpolation
(raw_text))
(end_tag
(tag_name)))
(text)
(end_tag (tag_name))
)
)



================================================================================
Interpolations - Attributes (https://vuejs.org/v2/guide/syntax.html#Attributes)
================================================================================
Expand Down
31 changes: 27 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ module.exports = grammar({
$.self_closing_tag,
),

template_element: $ => seq(
alias($.template_start_tag, $.start_tag),
repeat($._node),
$.end_tag,
template_element: $ => choice(
seq(
alias($.template_start_tag, $.start_tag),
repeat($._node),
$.end_tag,
),
seq(
alias($.template_start_tag_with_lang, $.start_tag),
optional($.raw_text),
$.end_tag,
),
),

script_element: $ => seq(
Expand Down Expand Up @@ -80,6 +87,12 @@ module.exports = grammar({
repeat(choice($.attribute, $.directive_attribute)),
">",
),
template_start_tag_with_lang: $ => seq(
"<",
alias($._template_start_tag_name, $.tag_name),
alias($.lang_attribute, $.attribute),
">",
),

script_start_tag: $ => seq(
"<",
Expand Down Expand Up @@ -124,6 +137,16 @@ module.exports = grammar({
),
)),
),
lang_attribute: $ => seq(
alias("lang", $.attribute_name),
optional(seq(
"=",
choice(
$.attribute_value,
$.quoted_attribute_value,
),
)),
),

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

Expand Down
144 changes: 127 additions & 17 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 27e8d92

Please sign in to comment.