-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Template Toolkit 2 (#1418)
* support for Template Toolkit 2 * optimized quoted string regexes * optimized double-quoted string regex * fully qualified tt2 plug-in names don't work Also use \w. * do not use empty character class See #1107. * put keyword tests in alphabetical order * ordered tt2 keywords alphabetically * removed redundant operator rule for tt2 * removed possibly existing old rules before inserti * indentation * allow backslash in front of lf in tt2 strings * indentation * avoid backtracking * escape xml special characters * indent with tab instead of spaces * greedy is no longer needed for variables Also use \w instead of explicit character class. * re-generated with gulp
- Loading branch information
Showing
17 changed files
with
565 additions
and
5 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(function(Prism) { | ||
|
||
Prism.languages.tt2 = Prism.languages.extend('clike', { | ||
comment: { | ||
pattern: /#.*|\[%#[\s\S]*?%\]/, | ||
lookbehind: true | ||
}, | ||
keyword: /\b(?:BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|ELSE|ELSIF|END|FILTER|FINAL|FOREACH|GET|IF|IN|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|TAGS|THROW|TRY|SWITCH|UNLESS|USE|WHILE|WRAPPER)\b/, | ||
punctuation: /[[\]{},()]/ | ||
}); | ||
|
||
delete Prism.languages.tt2['operator']; | ||
delete Prism.languages.tt2['variable']; | ||
Prism.languages.insertBefore('tt2', 'number', { | ||
operator: /=[>=]?|!=?|<=?|>=?|&&|\|\|?|\b(?:and|or|not)\b/, | ||
variable: { | ||
pattern: /[a-z]\w*(?:\s*\.\s*(?:\d+|\$?[a-z]\w*))*/i | ||
} | ||
}); | ||
|
||
delete Prism.languages.tt2['delimiter']; | ||
Prism.languages.insertBefore('tt2', 'keyword', { | ||
'delimiter': { | ||
pattern: /^(?:\[%|%%)-?|-?%]$/, | ||
alias: 'punctuation' | ||
} | ||
}); | ||
|
||
Prism.languages.insertBefore('tt2', 'string', { | ||
'single-quoted-string': { | ||
pattern: /'[^\\']*(?:\\[\s\S][^\\']*)*'/, | ||
greedy: true, | ||
alias: 'string' | ||
}, | ||
'double-quoted-string': { | ||
pattern: /"[^\\"]*(?:\\[\s\S][^\\"]*)*"/, | ||
greedy: true, | ||
alias: 'string', | ||
inside: { | ||
variable: { | ||
pattern: /\$(?:[a-z]\w*(?:\.(?:\d+|\$?[a-z]\w*))*)/i | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// The different types of TT2 strings "replace" the C-like standard string | ||
delete Prism.languages.tt2.string; | ||
|
||
Prism.hooks.add('before-tokenize', function(env) { | ||
var tt2Pattern = /\[%[\s\S]+?%\]/g; | ||
Prism.languages['markup-templating'].buildPlaceholders(env, 'tt2', tt2Pattern); | ||
}); | ||
|
||
Prism.hooks.add('after-tokenize', function(env) { | ||
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'tt2'); | ||
}); | ||
|
||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<h2>Comments</h2> | ||
<pre><code class="language-tt2">[%# this entire directive is ignored no | ||
matter how many lines it wraps onto | ||
%] | ||
[% # this is a comment | ||
theta = 20 # so is this | ||
rho = 30 # <aol>me too!</aol> | ||
%] | ||
</code></pre> | ||
|
||
<h2>Variables</h2> | ||
<pre><code class="language-tt2">[% text %] | ||
[% article.title %] | ||
[%= eat.whitespace.left %] | ||
[% eat.whitespace.right =%] | ||
[%= eat.whitespace.both =%] | ||
[% object.method() %]</code></pre> | ||
|
||
|
||
<h2>Conditionals and Loops</h2> | ||
<pre><code class="language-tt2">[% IF foo = bar %] | ||
this | ||
[% ELSE %] | ||
that | ||
[% END %] | ||
[% FOREACH post IN q.listPosts(lingua = "de") %] | ||
<a href="[% post.permalink %]">[% post.title | html %]</a> | ||
[% END %]</code></pre> | ||
|
||
<h2>Multiple Directives</h2> | ||
<pre><code class="language-tt2">[% IF title; | ||
INCLUDE header; | ||
ELSE; | ||
INCLUDE other/header title="Some Other Title"; | ||
END | ||
%]</code></pre> | ||
|
||
<h2>Operators</h2> | ||
<pre><code class="language-tt2">[% FOREACH post IN q.listPosts(lingua => 'de') %] | ||
[% post.title | myfilter(foo = "bar") %] | ||
[% END %]</code></pre> | ||
|
||
<h2>Known Limitations</h2> | ||
<ul> | ||
<li><a href="http://template-toolkit.org/docs/manual/Syntax.html#section_Outline_Tags"> | ||
Outline tags</a> are not supported.</li> | ||
<li>The arguments to | ||
<a href="http://template-toolkit.org/docs/manual/Directives.html#section_TAGS">TAGS</a> | ||
are usually misinterpreted</li> | ||
<li>In TT2, you can use keywords as identifiers where this is | ||
unambiguous. But these keywords will be highlighted as keywords, not | ||
as variables here.</li> | ||
<li>The | ||
<a href="http://template-toolkit.org/docs/manual/Config.html#section_ANYCASE">ANYCASE</a> | ||
option is not supported.</li> | ||
<li> | ||
Any number of backslashes in front of dollar signs inside of double quoted | ||
strings are ignored since the behavior of Template Toolkit 2.26 seems to be | ||
inconsistent. | ||
</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.