Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid: add simple empty keyword #2997

Merged
merged 1 commit into from Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/prism-liquid.js
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
@@ -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 ",
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
["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.