Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/testing.latex.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
((* extends "base.latex" *))

((* include "other.latex" ignore missing without context *))

((* if test and ('a' ~ 'b') is not none *))
((* macro func(arg1, arg2) *))
((* for x in whatever *))
((( x | fancy_filter )))
((* set test = true *))
((* endfor *))
((* endmacro *))
((* endif *))

((* import 'templates/something.j2' as sth *))
((* from 'funcs.latex.j2' import func as foo, bar *))

((* block test *)) test ((* endblock *))

((* set reply | wordwrap *))
Regarding your message:
((( message )))
((* endset *))

((* block main *))
((* set who_is_it = 'world' *))
hello ((( who_is_it | capitalize )))!
((* raw -*))
((* set who_is_it = 'world' *))
hello ((( who_is_it | capitalize )))!
((* endraw *))
((* endblock *))
8 changes: 5 additions & 3 deletions language-configuration-latex.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
["'", "'"],
["*", "*"],
["#", "#"]
],
"folding": {
"markers": {
"start": "\\(\\(\\*\\s*(block|filter|for|if|macro|raw)",
"end": "\\(\\(\\*\\s*end(block|filter|for|if|macro|raw)\\s*\\*\\)\\)"
"start": "\\(\\(\\*\\s*(autoescape|block|call|filter|for|if|macro|raw|set(?!\\s+[a-zA-Z_][a-zA-Z0-9_]*\\s*=)|with)\\b",
"end": "\\(\\(\\*\\s*end(autoescape|block|call|filter|for|if|macro|raw|set|with)\\b"
}
}
}
154 changes: 103 additions & 51 deletions syntaxes/jinja-latex.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@
"scopeName": "text.latex.jinja",
"comment": "Jinja Latex Templates",
"firstLineMatch": "^(\\(\\(\\* extends [\"'][^\"']+[\"'] \\*\\)\\)",
"foldingStartMarker": "(\\(\\(\\*\\s*(block|filter|for|if|macro|raw))",
"foldingStopMarker": "(\\(\\(\\*\\s*(endblock|endfilter|endfor|endif|endmacro|endraw)\\s*\\*\\)\\))",
"patterns": [
{
"include": "text.tex.latex"
},
{
"begin": "(\\(\\(\\*)\\s*(raw)\\s*(\\*\\)\\))",
"begin": "(\\(\\(\\*)\\s*(raw)\\s*(-?\\*\\)\\))",
"captures": {
"1": {
"name": "entity.other.jinja.delimiter.tag"
"name": "keyword.control.jinja.delimiter.statement"
},
"2": {
"name": "keyword.control.jinja"
},
"3": {
"name": "entity.other.jinja.delimiter.tag"
"name": "keyword.control.jinja.delimiter.statement"
}
},
"end": "(\\(\\(\\*)\\s*(endraw)\\s*(\\*\\)\\))",
"name": "comment.block.jinja.raw"
"name": "markup.raw.jinja"
},
{
"begin": "\\(\\(#-?",
"begin": "\\(\\(#[-+]?",
"captures": [
{
"name": "entity.other.jinja.delimiter.comment"
}
],
"end": "-?#\\)\\)",
"end": "[-+]?#\\)\\)",
"name": "comment.block.jinja"
},
{
"begin": "\\(\\(\\(-?",
"begin": "\\(\\(\\([-+]?",
"captures": [
{
"name": "variable.entity.other.jinja.delimiter"
"name": "keyword.control.jinja.delimiter.expression"
}
],
"end": "-?\\)\\)\\)",
"end": "[-+]?\\)\\)\\)",
"name": "variable.meta.scope.jinja",
"patterns": [
{
Expand All @@ -51,14 +49,14 @@
]
},
{
"begin": "\\(\\(\\*-?",
"begin": "\\(\\(\\*[-+]?",
"captures": [
{
"name": "entity.other.jinja.delimiter.tag"
"name": "keyword.control.jinja.delimiter.statement"
}
],
"end": "-?\\*\\)\\)",
"name": "meta.scope.jinja.tag",
"end": "[-+]?\\*\\)\\)",
"name": "meta.scope.jinja.statement",
"patterns": [
{
"include": "#expression"
Expand All @@ -72,6 +70,7 @@
"name": "constant.character.escape.hex.jinja"
},
"escaped_unicode_char": {
"match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})",
"captures": {
"1": {
"name": "constant.character.escape.unicode.16-bit-hex.jinja"
Expand All @@ -82,56 +81,121 @@
"3": {
"name": "constant.character.escape.unicode.name.jinja"
}
},
"match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})"
}
},
"expression": {
"patterns": [
{
"match": "\\s*\\b(from)\\s+(([\"'])[^\"']+\\3)\\s+(import)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "keyword.control.jinja"
"name": "keyword.control.import.jinja"
},
"2": {
"name": "variable.other.jinja.block"
"name": "string.quoted.double.jinja"
},
"4": {
"name": "keyword.control.import.jinja"
},
"5": {
"name": "variable.other.jinja"
}
},
"match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b"
}
},
{
"match": "\\s*\\b(import)\\s+(([\"'])[^\"']+\\3)",
"captures": {
"1": {
"name": "keyword.control.jinja"
"name": "keyword.control.import.jinja"
},
"2": {
"name": "variable.other.jinja.filter"
"name": "string.quoted.double.jinja"
}
},
"match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b"
}
},
{
"match": "\\b(as)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "keyword.control.jinja"
"name": "keyword.control.import.jinja"
},
"2": {
"name": "variable.other.jinja"
}
}
},
{
"match": "\\s*\\b(block)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "storage.type.block.jinja"
},
"2": {
"name": "variable.other.jinja.test"
"name": "entity.name.block.jinja"
}
},
"match": "\\s*\\b(is)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b"
}
},
{
"match": "\\s*\\b(macro)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "storage.type.macro.jinja"
},
"2": {
"name": "entity.name.macro.jinja"
}
}
},
{
"match": "\\s*\\b(set)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "storage.type.variable.jinja"
},
"2": {
"name": "variable.other.jinja"
}
}
},
{
"match": "\\b(end(block|macro|set))\\b",
"name": "storage.type.jinja"
},
{
"match": "\\s*\\b(filter)\\s+([a-zA-Z_][a-zA-Z0-9_]*)\\b",
"captures": {
"1": {
"name": "keyword.control.jinja"
},
"2": {
"name": "entity.name.filter.jinja"
}
},
"match": "(?<=\\(\\(\\%-|\\(\\(\\%)\\s*\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?!\\s*[,=])"
}
},
{
"match": "\\b(and|else|if|in|import|not|or|recursive|with(out)?\\s+context)\\b",
"match": "\\b(with(out)?\\s+context|elif|else|endfilter|(end)?(autoescape|for|if|with)|extends|include|recursive|ignore missing)\\b",
"name": "keyword.control.jinja"
},
{
"match": "(==|<=|=>|<|>|!=)",
"name": "keyword.operator.comparison.jinja"
},
{
"match": "=",
"name": "keyword.operator.assignment.jinja"
},
{
"match": "\\b(and|or|not)\\b",
"name": "keyword.operator.logical.jinja"
},
{
"match": "(\\+|\\-|\\*\\*|\\*|//|/|%)",
"name": "keyword.operator.arithmetic.jinja"
},
{
"match": "~|\\b(in|is)\\b",
"name": "keyword.operator.other.jinja"
},
{
"match": "\\b(true|false|none)\\b",
"name": "constant.language.jinja"
Expand All @@ -145,30 +209,26 @@
"name": "variable.other.jinja"
},
{
"match": "(\\+|\\-|\\*\\*|\\*|//|/|%)",
"name": "keyword.operator.arithmetic.jinja"
},
{
"match": "(\\|)\\s*([a-zA-Z_][a-zA-Z0-9_]*)",
"captures": {
"1": {
"name": "punctuation.other.jinja"
"name": "keyword.operator.other.jinja"
},
"2": {
"name": "variable.other.jinja.filter"
"name": "entity.name.filter.jinja"
}
},
"match": "(\\|)([a-zA-Z_][a-zA-Z0-9_]*)"
}
},
{
"match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)",
"captures": {
"1": {
"name": "punctuation.other.jinja"
"name": "keyword.operator.other.jinja"
},
"2": {
"name": "variable.other.jinja.attribute"
}
},
"match": "(\\.)([a-zA-Z_][a-zA-Z0-9_]*)"
}
},
{
"begin": "\\[",
Expand Down Expand Up @@ -216,14 +276,6 @@
"match": "(\\.|:|\\||,)",
"name": "punctuation.other.jinja"
},
{
"match": "(==|<=|=>|<|>|!=)",
"name": "keyword.operator.comparison.jinja"
},
{
"match": "=",
"name": "keyword.operator.assignment.jinja"
},
{
"begin": "\"",
"beginCaptures": [
Expand Down