diff --git a/src/jinja.ts b/src/jinja.ts index 342f957..30a73ad 100644 --- a/src/jinja.ts +++ b/src/jinja.ts @@ -56,7 +56,9 @@ export type Keyword = | "from" | "extends" | "block" - | "endblock"; + | "endblock" + | "with" + | "endwith"; export const nonClosingStatements = [ "else", diff --git a/src/parser.ts b/src/parser.ts index eacf5d5..dbbb6b8 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -12,7 +12,7 @@ import { const NOT_FOUND = -1; const regex = - /(?
(?\n)?(\s*?))(? {{\s*(? '([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(? [-+]?)\s*(? (? for|endfor|if|else|elif|endif|macro|endmacro|call|endcall|filter|endfilter|set|endset|include|import|from|extends|block|endblock)('([^']|\\')*'|"([^"]|\\")*"|[\S\s])*?)\s*(? [-+]?)%}|(? {#[\S\s]*?#})|(? <(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(? <(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(? [\s\S]*))/; + /(? (?\n)?(\s*?))(? {{\s*(? '([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(? [-+]?)\s*(? (? 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*(? [-+]?)%}|(? {#[\S\s]*?#})|(? <(script)((?!<)[\s\S])*>((?!<\/script)[\s\S])*?{{[\s\S]*?<\/(script)>)|(? <(style)((?!<)[\s\S])*>((?!<\/style)[\s\S])*?{{[\s\S]*?<\/(style)>)|(? [\s\S]*))/; export const parse: Parser ["parse"] = (text) => { const statementStack: Statement[] = []; diff --git a/test/cases/statement_with/expected.html b/test/cases/statement_with/expected.html new file mode 100644 index 0000000..6efd063 --- /dev/null +++ b/test/cases/statement_with/expected.html @@ -0,0 +1,4 @@ +{{ obj.method("argument")|default("", True) }} +{% with text='text', version=1 %} + {% include 'directory/template.jinja2' %} +{% endwith %} diff --git a/test/cases/statement_with/input.html b/test/cases/statement_with/input.html new file mode 100644 index 0000000..7872ca7 --- /dev/null +++ b/test/cases/statement_with/input.html @@ -0,0 +1,4 @@ +{{ obj.method("argument")|default("", True) }} +{% with text='text', version=1 %} + {% include 'directory/template.jinja2' %} +{% endwith %} \ No newline at end of file