add with statement support
This commit is contained in:
parent
7415f62e8b
commit
288384e105
4 changed files with 12 additions and 2 deletions
|
@ -56,7 +56,9 @@ export type Keyword =
|
|||
| "from"
|
||||
| "extends"
|
||||
| "block"
|
||||
| "endblock";
|
||||
| "endblock"
|
||||
| "with"
|
||||
| "endwith";
|
||||
|
||||
export const nonClosingStatements = [
|
||||
"else",
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
const NOT_FOUND = -1;
|
||||
|
||||
const regex =
|
||||
/(?<pre>(?<newline>\n)?(\s*?))(?<node>{{\s*(?<expression>'([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(?<startDelimiter>[-+]?)\s*(?<statement>(?<keyword>for|endfor|if|else|elif|endif|macro|endmacro|call|endcall|filter|endfilter|set|endset|include|import|from|extends|block|endblock)('([^']|\\')*'|"([^"]|\\")*"|[\S\s])*?)\s*(?<endDelimiter>[-+]?)%}|(?<comment>{#[\S\s]*?#})|(?<scriptBlock><(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(?<styleBlock><(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(?<ignoreBlock><!-- prettier-ignore-start -->[\s\S]*<!-- prettier-ignore-end -->))/;
|
||||
/(?<pre>(?<newline>\n)?(\s*?))(?<node>{{\s*(?<expression>'([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(?<startDelimiter>[-+]?)\s*(?<statement>(?<keyword>for|endfor|if|else|elif|endif|macro|endmacro|call|endcall|filter|endfilter|set|endset|include|import|from|extends|block|endblock|with|endwith)('([^']|\\')*'|"([^"]|\\")*"|[\S\s])*?)\s*(?<endDelimiter>[-+]?)%}|(?<comment>{#[\S\s]*?#})|(?<scriptBlock><(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(?<styleBlock><(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(?<ignoreBlock><!-- prettier-ignore-start -->[\s\S]*<!-- prettier-ignore-end -->))/;
|
||||
|
||||
export const parse: Parser<Node>["parse"] = (text) => {
|
||||
const statementStack: Statement[] = [];
|
||||
|
|
4
test/cases/statement_with/expected.html
Normal file
4
test/cases/statement_with/expected.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{ obj.method("argument")|default("", True) }}
|
||||
{% with text='text', version=1 %}
|
||||
{% include 'directory/template.jinja2' %}
|
||||
{% endwith %}
|
4
test/cases/statement_with/input.html
Normal file
4
test/cases/statement_with/input.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{ obj.method("argument")|default("", True) }}
|
||||
{% with text='text', version=1 %}
|
||||
{% include 'directory/template.jinja2' %}
|
||||
{% endwith %}
|
Loading…
Reference in a new issue