Liquid: Added `empty` keyword (#2997)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
diff --git a/components/prism-liquid.js b/components/prism-liquid.js
index 487dcc5..b337c19 100644
--- a/components/prism-liquid.js
+++ b/components/prism-liquid.js
@@ -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) {
diff --git a/components/prism-liquid.min.js b/components/prism-liquid.min.js
index 9afc80e..f33aafe 100644
--- a/components/prism-liquid.min.js
+++ b/components/prism-liquid.min.js
@@ -1 +1 @@
-Prism.languages.liquid={comment:{pattern:/(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,lookbehind:!0},delimiter:{pattern:/^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,alias:"punctuation"},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},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:!0,alias:"filter"},{pattern:/(\.\s*)(?:first|last|size)/,lookbehind:!0}],boolean:/\b(?:true|false|nil)\b/,range:{pattern:/\.\./,alias:"operator"},number:/\b\d+(?:\.\d+)?\b/,operator:/[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|or|contains(?=\s))\b/,punctuation:/[.,\[\]()]/},Prism.hooks.add("before-tokenize",function(e){var r=!1;Prism.languages["markup-templating"].buildPlaceholders(e,"liquid",/\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g,function(e){var n=/^\{%-?\s*(\w+)/.exec(e);if(n){var t=n[1];if("raw"===t&&!r)return r=!0;if("endraw"===t)return!(r=!1)}return!r})}),Prism.hooks.add("after-tokenize",function(e){Prism.languages["markup-templating"].tokenizePlaceholders(e,"liquid")});
\ No newline at end of file
+Prism.languages.liquid={comment:{pattern:/(^\{%\s*comment\s*%\})[\s\S]+(?=\{%\s*endcomment\s*%\}$)/,lookbehind:!0},delimiter:{pattern:/^\{(?:\{\{|[%\{])-?|-?(?:\}\}|[%\}])\}$/,alias:"punctuation"},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},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:!0,alias:"filter"},{pattern:/(\.\s*)(?:first|last|size)/,lookbehind:!0}],boolean:/\b(?:true|false|nil)\b/,range:{pattern:/\.\./,alias:"operator"},number:/\b\d+(?:\.\d+)?\b/,operator:/[!=]=|<>|[<>]=?|[|?:=-]|\b(?:and|or|contains(?=\s))\b/,punctuation:/[.,\[\]()]/,empty:{pattern:/\bempty\b/,alias:"keyword"}},Prism.hooks.add("before-tokenize",function(e){var r=!1;Prism.languages["markup-templating"].buildPlaceholders(e,"liquid",/\{%\s*comment\s*%\}[\s\S]*?\{%\s*endcomment\s*%\}|\{(?:%[\s\S]*?%|\{\{[\s\S]*?\}\}|\{[\s\S]*?\})\}/g,function(e){var n=/^\{%-?\s*(\w+)/.exec(e);if(n){var t=n[1];if("raw"===t&&!r)return r=!0;if("endraw"===t)return!(r=!1)}return!r})}),Prism.hooks.add("after-tokenize",function(e){Prism.languages["markup-templating"].tokenizePlaceholders(e,"liquid")});
\ No newline at end of file
diff --git a/tests/languages/liquid/empty_feature.test b/tests/languages/liquid/empty_feature.test
new file mode 100644
index 0000000..bfc7fef
--- /dev/null
+++ b/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 ",
+ ["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.