-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
22 changed files
with
1,287 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,96 @@ | ||
(function (Prism) { | ||
var stringPattern = /(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/; | ||
var numberPattern = /\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b|\b0x[\dA-F]+\b/; | ||
|
||
Prism.languages.soy = { | ||
'comment': [ | ||
/\/\*[\s\S]*?\*\//, | ||
{ | ||
pattern: /(\s)\/\/.*/, | ||
lookbehind: true, | ||
greedy: true | ||
} | ||
], | ||
'command-arg': { | ||
pattern: /({+\/?\s*(?:alias|call|delcall|delpackage|deltemplate|namespace|template)\s+)\.?[\w.]+/, | ||
lookbehind: true, | ||
alias: 'string', | ||
inside: { | ||
'punctuation': /\./ | ||
} | ||
}, | ||
'parameter': { | ||
pattern: /({+\/?\s*@?param\??\s+)\.?[\w.]+/, | ||
lookbehind: true, | ||
alias: 'variable' | ||
}, | ||
'keyword': [ | ||
{ | ||
pattern: /({+\/?[^\S\r\n]*)(?:\\[nrt]|alias|call|case|css|default|delcall|delpackage|deltemplate|else(?:if)?|fallbackmsg|for(?:each)?|if(?:empty)?|lb|let|literal|msg|namespace|nil|@?param\??|rb|sp|switch|template|xid)/, | ||
lookbehind: true | ||
}, | ||
/\b(?:any|as|attributes|bool|css|float|in|int|js|html|list|map|null|number|string|uri)\b/ | ||
], | ||
'delimiter': { | ||
pattern: /^{+\/?|\/?}+$/, | ||
alias: 'punctuation' | ||
}, | ||
'property': /\w+(?==)/, | ||
'variable': { | ||
pattern: /\$[^\W\d]\w*(?:\??(?:\.\w+|\[[^\]]+]))*/, | ||
inside: { | ||
'string': { | ||
pattern: stringPattern, | ||
greedy: true | ||
}, | ||
'number': numberPattern, | ||
'punctuation': /[\[\].?]/ | ||
} | ||
}, | ||
'string': { | ||
pattern: stringPattern, | ||
greedy: true | ||
}, | ||
'function': [ | ||
/\w+(?=\()/, | ||
{ | ||
pattern: /(\|[^\S\r\n]*)\w+/, | ||
lookbehind: true | ||
} | ||
], | ||
'boolean': /\b(?:true|false)\b/, | ||
'number': numberPattern, | ||
'operator': /\?:?|<=?|>=?|==?|!=|[+*/%-]|\b(?:and|not|or)\b/, | ||
'punctuation': /[{}()\[\]|.,:]/ | ||
}; | ||
|
||
// Tokenize all inline Soy expressions | ||
Prism.hooks.add('before-tokenize', function (env) { | ||
var soyPattern = /{{.+?}}|{.+?}|\s\/\/.*|\/\*[\s\S]*?\*\//g; | ||
var soyLitteralStart = '{literal}'; | ||
var soyLitteralEnd = '{/literal}'; | ||
var soyLitteralMode = false; | ||
|
||
Prism.languages['markup-templating'].buildPlaceholders(env, 'soy', soyPattern, function (match) { | ||
// Soy tags inside {literal} block are ignored | ||
if (match === soyLitteralEnd) { | ||
soyLitteralMode = false; | ||
} | ||
|
||
if (!soyLitteralMode) { | ||
if (match === soyLitteralStart) { | ||
soyLitteralMode = true; | ||
} | ||
|
||
return true; | ||
} | ||
return false; | ||
}); | ||
}); | ||
|
||
// Re-insert the tokens after tokenizing | ||
Prism.hooks.add('after-tokenize', function (env) { | ||
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'soy'); | ||
}); | ||
|
||
}(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,36 @@ | ||
<h2>Comments</h2> | ||
<pre><code>/* Multi-line | ||
comment */ | ||
// This is a comment with <p>some markup</p> in it</code></pre> | ||
|
||
<h2>Variable</h2> | ||
<pre><code>{$name} | ||
{$folders[0]['name']} | ||
{$aaa?.bbb.ccc?[0]}</code></pre> | ||
|
||
<h2>Commands</h2> | ||
<pre><code>{template .helloNames} | ||
// Greet the person. | ||
{call .helloName data="all" /}<br> | ||
// Greet the additional people. | ||
{foreach $additionalName in $additionalNames} | ||
{call .helloName} | ||
{param name: $additionalName /} | ||
{/call} | ||
{if not isLast($additionalName)} | ||
<br> // break after every line except the last | ||
{/if} | ||
{ifempty} | ||
No additional people to greet. | ||
{/foreach} | ||
{/template}</code></pre> | ||
|
||
<h2>Functions and print directives</h2> | ||
<pre><code>{if length($items) > 5} | ||
{$foo|changeNewlineToBr} | ||
{$bar|truncate: 4, false}</code></pre> | ||
|
||
<h2>Literal section</h2> | ||
<pre><code>{literal} | ||
This is not a {$variable} | ||
{/literal}</code></pre> |
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.