diff --git a/src/jinja.ts b/src/jinja.ts index 30a73ad..f4dab32 100644 --- a/src/jinja.ts +++ b/src/jinja.ts @@ -22,7 +22,7 @@ export type Delimiter = "" | "-" | "+"; export interface Statement extends Node { type: "statement"; - keyword: Keyword; + keyword: string; delimiter: Delimiter; } @@ -36,30 +36,6 @@ export interface IgnoreBlock extends Node { type: "ignore"; } -export type Keyword = - | "for" - | "endfor" - | "if" - | "else" - | "elif" - | "endif" - | "macro" - | "endmacro" - | "call" - | "endcall" - | "filter" - | "endfilter" - | "set" - | "endset" - | "include" - | "import" - | "from" - | "extends" - | "block" - | "endblock" - | "with" - | "endwith"; - export const nonClosingStatements = [ "else", "elif", diff --git a/src/parser.ts b/src/parser.ts index dbbb6b8..841af95 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1,7 +1,6 @@ import { Parser } from "prettier"; import { Delimiter, - Keyword, Node, Placeholder, Statement, @@ -12,7 +11,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|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]*))/; + /(? (?\n)?(\s*?))(? {{\s*(? '([^']|\\')*'|"([^"]|\\")*"|[\S\s]*?)\s*}}|{%(? [-+]?)\s*(? (? \w+)('([^']|\\')*'|"([^"]|\\")*"|[\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[] = []; @@ -86,7 +85,7 @@ export const parse: Parser ["parse"] = (text) => { } if (statement) { - const keyword = match.groups.keyword as Keyword; + const keyword = match.groups.keyword; const delimiter = (match.groups.startDelimiter || match.groups.endDelimiter) as Delimiter; diff --git a/test/cases/statement_unknown/expected.html b/test/cases/statement_unknown/expected.html new file mode 100644 index 0000000..46e7005 --- /dev/null +++ b/test/cases/statement_unknown/expected.html @@ -0,0 +1,3 @@ +{% foo %} + Hello
+{% endfoo %} diff --git a/test/cases/statement_unknown/input.html b/test/cases/statement_unknown/input.html new file mode 100644 index 0000000..cfaaa88 --- /dev/null +++ b/test/cases/statement_unknown/input.html @@ -0,0 +1,5 @@ +{%foo %} +Hello
+{% endfoo + + %} \ No newline at end of file