Skip to content

Commit

Permalink
Liquid: Added empty keyword (#2997)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaKXz authored Jul 15, 2021
1 parent e997dd3 commit fe3bc52
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
6 changes: 5 additions & 1 deletion components/prism-liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ Prism.languages.liquid = {
// 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': /[.,\[\]()]/
'punctuation': /[.,\[\]()]/,
'empty': {
pattern: /\bempty\b/,
alias: 'keyword'
},
};

Prism.hooks.add('before-tokenize', function (env) {
Expand Down
2 changes: 1 addition & 1 deletion components/prism-liquid.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions tests/languages/liquid/empty_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{% unless pages == empty %}
<!-- This will only print if the page with handle "about" is not empty -->
<h1>{{ pages.frontpage.not_empty_title }}</h1>
<div>{{ pages.frontpage.content }}</div>
{% endunless %}

----------------------------------------------------

[
["liquid", [
["delimiter", "{%"],
["keyword", "unless"],
" pages ",
["operator", "=="],
["empty", "empty"],
["delimiter", "%}"]
]],

["comment", "<!-- This will only print if the page with handle \"about\" is not empty -->"],

["tag", [
["tag", [
["punctuation", "<"],
"h1"
]],
["punctuation", ">"]
]],
["liquid", [
["delimiter", "{{"],
" pages",
["punctuation", "."],
"frontpage",
["punctuation", "."],
"not_empty_title ",
["delimiter", "}}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"h1"
]],
["punctuation", ">"]
]],

["tag", [
["tag", [
["punctuation", "<"],
"div"
]],
["punctuation", ">"]
]],
["liquid", [
["delimiter", "{{"],
" pages",
["punctuation", "."],
"frontpage",
["punctuation", "."],
"content ",
["delimiter", "}}"]
]],
["tag", [
["tag", [
["punctuation", "</"],
"div"
]],
["punctuation", ">"]
]],

["liquid", [
["delimiter", "{%"],
["keyword", "endunless"],
["delimiter", "%}"]
]]
]

----------------------------------------------------

Test for the 'empty' keyword / special thing.

0 comments on commit fe3bc52

Please sign in to comment.