-
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.
Liquid: Added Markup support, missing tokens, and other improvements (#…
- Loading branch information
1 parent
abab910
commit ac1d12f
Showing
16 changed files
with
921 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -732,6 +732,7 @@ | |
}, | ||
"liquid": { | ||
"title": "Liquid", | ||
"require": "markup-templating", | ||
"owner": "cinhtau" | ||
}, | ||
"lisp": { | ||
|
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 |
---|---|---|
@@ -1,12 +1,61 @@ | ||
Prism.languages.liquid = { | ||
'keyword': /\b(?:comment|endcomment|if|elsif|else|endif|unless|endunless|for|endfor|case|endcase|when|in|break|assign|continue|limit|offset|range|reversed|raw|endraw|capture|endcapture|tablerow|endtablerow)\b/, | ||
'number': /\b0b[01]+\b|\b0x(?:\.[\da-fp-]+|[\da-f]+(?:\.[\da-fp-]+)?)\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?[df]?/i, | ||
'operator': { | ||
pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m, | ||
'comment': { | ||
pattern: /(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/, | ||
lookbehind: true | ||
}, | ||
'function': { | ||
pattern: /(^|[\s;|&])(?:append|prepend|capitalize|cycle|cols|increment|decrement|abs|at_least|at_most|ceil|compact|concat|date|default|divided_by|downcase|escape|escape_once|first|floor|join|last|lstrip|map|minus|modulo|newline_to_br|plus|remove|remove_first|replace|replace_first|reverse|round|rstrip|size|slice|sort|sort_natural|split|strip|strip_html|strip_newlines|times|truncate|truncatewords|uniq|upcase|url_decode|url_encode|include|paginate)(?=$|[\s;|&])/, | ||
lookbehind: true | ||
} | ||
'delimiter': { | ||
pattern: /^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/, | ||
alias: 'punctuation' | ||
}, | ||
'string': { | ||
pattern: /"[^"]*"|'[^']*'/, | ||
greedy: true | ||
}, | ||
'keyword': /\b(?:as|assign|break|continue|cycle|decrement|echo|else|elsif|(?:end)?(?:capture|case|comment|for|form|if|paginate|style|raw|tablerow|unless)|in|include|increment|limit|liquid|offset|range|render|reversed|section|when|with)\b/, | ||
'function': [ | ||
{ | ||
pattern: /(\|\s*)\w+/, | ||
lookbehind: true, | ||
alias: 'filter' | ||
}, | ||
{ | ||
// array functions | ||
pattern: /(\.\s*)(?:first|last|size)/, | ||
lookbehind: true | ||
} | ||
], | ||
'boolean': /\b(?:true|false|nil)\b/, | ||
'range': { | ||
pattern: /\.\./, | ||
alias: 'operator' | ||
}, | ||
// https://github.com/Shopify/liquid/blob/698f5e0d967423e013f6169d9111bd969bd78337/lib/liquid/lexer.rb#L21 | ||
'number': /\b\d+(?:\.\d+)?\b/, | ||
'operator': /[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|or|contains(?=\s))\b/, | ||
'punctuation': /[.,\[\]()]/ | ||
}; | ||
|
||
Prism.hooks.add('before-tokenize', function (env) { | ||
var liquidPattern = /\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g; | ||
var insideRaw = false; | ||
|
||
Prism.languages['markup-templating'].buildPlaceholders(env, 'liquid', liquidPattern, function (match) { | ||
var tagMatch = /^\{%-?\s*(\w+)/.exec(match); | ||
if (tagMatch) { | ||
var tag = tagMatch[1]; | ||
if (tag === 'raw' && !insideRaw) { | ||
insideRaw = true; | ||
return true; | ||
} else if (tag === 'endraw') { | ||
insideRaw = false; | ||
return true; | ||
} | ||
} | ||
|
||
return !insideRaw; | ||
}); | ||
}); | ||
|
||
Prism.hooks.add('after-tokenize', function (env) { | ||
Prism.languages['markup-templating'].tokenizePlaceholders(env, 'liquid'); | ||
}); |
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
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,26 @@ | ||
{% if true and false and false or true %} | ||
|
||
{% nil %} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["liquid", [ | ||
["delimiter", "{%"], | ||
["keyword", "if"], | ||
["boolean", "true"], | ||
["operator", "and"], | ||
["boolean", "false"], | ||
["operator", "and"], | ||
["boolean", "false"], | ||
["operator", "or"], | ||
["boolean", "true"], | ||
["delimiter", "%}"] | ||
]], | ||
|
||
["liquid", [ | ||
["delimiter", "{%"], | ||
["boolean", "nil"], | ||
["delimiter", "%}"] | ||
]] | ||
] |
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 @@ | ||
My name is Wilson Abercrombie{% comment %}, esquire{% endcomment %}. | ||
|
||
{% assign verb = "turned" %} | ||
{% comment %} | ||
{% assign verb = "converted" %} | ||
{% endcomment %} | ||
Anything you put between {% comment %} and {% endcomment %} tags | ||
is {{ verb }} into a comment. | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
"My name is Wilson Abercrombie", | ||
["liquid", [ | ||
["delimiter", "{%"], | ||
["keyword", "comment"], | ||
["delimiter", "%}"], | ||
["comment", ", esquire"], | ||
["delimiter", "{%"], | ||
["keyword", "endcomment"], | ||
["delimiter", "%}"] | ||
]], | ||
".\r\n\r\n", | ||
|
||
["liquid", [ | ||
["delimiter", "{%"], | ||
["keyword", "assign"], | ||
" verb ", | ||
["operator", "="], | ||
["string", "\"turned\""], | ||
["delimiter", "%}"] | ||
]], | ||
|
||
["liquid", [ | ||
["delimiter", "{%"], | ||
["keyword", "comment"], | ||
["delimiter", "%}"], | ||
["comment", "\r\n{% assign verb = \"converted\" %}\r\n"], | ||
["delimiter", "{%"], | ||
["keyword", "endcomment"], | ||
["delimiter", "%}"] | ||
]], | ||
|
||
"\r\nAnything you put between ", | ||
["liquid", [ | ||
["delimiter", "{%"], | ||
["keyword", "comment"], | ||
["delimiter", "%}"], | ||
["comment", " and "], | ||
["delimiter", "{%"], | ||
["keyword", "endcomment"], | ||
["delimiter", "%}"] | ||
]], | ||
" tags\r\nis ", | ||
["liquid", [ | ||
["delimiter", "{{"], | ||
" verb ", | ||
["delimiter", "}}"] | ||
]], | ||
" into a comment." | ||
] |
Oops, something went wrong.