Basic Syntax Highlighting for Liquid (#1326) * Basic Syntax Highlighting for Liquid [Liquid](http://shopify.github.io/liquid/), a template language by shopify It is used in Jekyll and add some basic highlighting * fix typo * Corrections and Improvements - move liquid above livescript - regnerate languages for show language plugin, after fixing typo - keywords - tablerow and endtablerow are keywords - add all keywords in test - add funtcions test * Minor Corrections comply to whitespace settings, use tabs instead of spaces for indentation
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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
diff --git a/components.js b/components.js
index 4472716..20ec389 100644
--- a/components.js
+++ b/components.js
@@ -350,6 +350,10 @@ var components = {
"require": "css",
"owner": "Golmote"
},
+ "liquid": {
+ "title": "Liquid",
+ "owner": "cinhtau"
+ },
"livescript": {
"title": "LiveScript",
"owner": "Golmote"
diff --git a/components/prism-liquid.js b/components/prism-liquid.js
new file mode 100644
index 0000000..0c23178
--- /dev/null
+++ b/components/prism-liquid.js
@@ -0,0 +1,12 @@
+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-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,
+ 'operator': {
+ pattern: /(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,
+ 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
+ }
+};
diff --git a/components/prism-liquid.min.js b/components/prism-liquid.min.js
new file mode 100644
index 0000000..1422054
--- /dev/null
+++ b/components/prism-liquid.min.js
@@ -0,0 +1 @@
+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-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+(?:e[+-]?\d+)?[df]?\b/i,operator:{pattern:/(^|[^.])(?:\+[+=]?|-[-=]?|!=?|<<?=?|>>?>?=?|==?|&[&=]?|\|[|=]?|\*=?|\/=?|%=?|\^=?|[?:~])/m,lookbehind:!0},"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:!0}};
\ No newline at end of file
diff --git a/examples/prism-liquid.html b/examples/prism-liquid.html
new file mode 100644
index 0000000..46951c3
--- /dev/null
+++ b/examples/prism-liquid.html
@@ -0,0 +1,78 @@
+<h1>Liquid</h1>
+<p>To use this language, use the class "language-liquid".</p>
+
+<h2>Comments</h2>
+<pre><code>{% comment %}This is a comment{% endcomment %}</code></pre>
+
+<h2>Control Flow</h2>
+
+Liquid provides multiple control flow statements.
+
+<h3>if</h3>
+<pre><code>
+{% if customer.name == 'kevin' %}
+ Hey Kevin!
+{% elsif customer.name == 'anonymous' %}
+ Hey Anonymous!
+{% else %}
+ Hi Stranger!
+{% endif %}
+</code></pre>
+
+<h3>unless</h3>
+
+The opposite of <code>if</code> – executes a block of code only if a certain condition is not met.
+
+<pre><code>
+{% unless product.title == 'Awesome Shoes' %}
+These shoes are not awesome.
+{% endunless %}
+</code></pre>
+
+<h3>case</h3>
+
+Creates a switch statement to compare a variable with different values. <code>case</code> initializes the switch statement, and <code>when</code> compares its values.
+
+<pre><code>
+{% assign handle = 'cake' %}
+{% case handle %}
+ {% when 'cake' %}
+ This is a cake
+ {% when 'cookie' %}
+ This is a cookie
+ {% else %}
+ This is not a cake nor a cookie
+{% endcase %}
+</code></pre>
+
+<h3>for</h3>
+
+Repeatedly executes a block of code.
+
+break = Causes the loop to stop iterating when it encounters the break tag.
+continue = Causes the loop to skip the current iteration when it encounters the continue tag.
+
+<pre><code>
+{% for i in (1..10) %}
+ {% if i == 4 %}
+ {% break %}
+ {% elsif i == 6 %}
+ {% continue %}
+ {% else %}
+ {{ i }}
+ {% endif %}
+{% endfor %}
+</code></pre>
+
+<h3>range</h3>
+
+<pre><code>
+{% for i in (3..5) %}
+ {{ i }}
+{% endfor %}
+
+{% assign num = 4 %}
+{% for i in (1..num) %}
+ {{ i }}
+{% endfor %}
+</code></pre>
diff --git a/tests/languages/liquid/function_feature.test b/tests/languages/liquid/function_feature.test
new file mode 100644
index 0000000..4689ef6
--- /dev/null
+++ b/tests/languages/liquid/function_feature.test
@@ -0,0 +1,39 @@
+abs append at_least at_most
+capitalize ceil cols compact concat cycle
+date decrement default divided_by downcase
+escape escape_once
+first floor
+include increment
+join
+last lstrip
+map minus modulo
+newline_to_br
+paginate plus prepend
+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
+
+----------------------------------------------------
+
+[
+ ["function", "abs"], ["function", "append"], ["function", "at_least"], ["function", "at_most"],
+ ["function", "capitalize"], ["function", "ceil"], ["function", "cols"], ["function", "compact"], ["function", "concat"], ["function", "cycle"],
+ ["function", "date"], ["function", "decrement"], ["function", "default"], ["function", "divided_by"], ["function", "downcase"],
+ ["function", "escape"], ["function", "escape_once"],
+ ["function", "first"], ["function", "floor"],
+ ["function", "include"], ["function", "increment"],
+ ["function", "join"],
+ ["function", "last"], ["function", "lstrip"],
+ ["function", "map"], ["function", "minus"], ["function", "modulo"],
+ ["function", "newline_to_br"],
+ ["function", "paginate"], ["function", "plus"], ["function", "prepend"],
+ ["function", "remove"], ["function", "remove_first"], ["function", "replace"], ["function", "replace_first"], ["function", "reverse"], ["function", "round"], ["function", "rstrip"],
+ ["function", "size"], ["function", "slice"], ["function", "sort"], ["function", "sort_natural"], ["function", "split"], ["function", "strip"], ["function", "strip_html"], ["function", "strip_newlines"],
+ ["function", "times"], ["function", "truncate"], ["function", "truncatewords"],
+ ["function", "uniq"], ["function", "upcase"], ["function", "url_decode"], ["function", "url_encode"]
+]
+
+----------------------------------------------------
+
+Checks for functions. Also checks for unicode characters in identifiers.
diff --git a/tests/languages/liquid/keyword_feature.test b/tests/languages/liquid/keyword_feature.test
new file mode 100644
index 0000000..84ffabd
--- /dev/null
+++ b/tests/languages/liquid/keyword_feature.test
@@ -0,0 +1,29 @@
+comment endcomment
+if else elsif endif
+unless endunless
+for endfor in break
+case endcase when
+assign continue
+limit offset range reversed
+raw endraw
+capture endcapture
+tablerow endtablerow
+
+----------------------------------------------------
+
+[
+ ["keyword", "comment"], ["keyword", "endcomment"],
+ ["keyword", "if"], ["keyword", "else"], ["keyword", "elsif"], ["keyword", "endif"],
+ ["keyword", "unless"], ["keyword", "endunless"],
+ ["keyword", "for"], ["keyword", "endfor"], ["keyword", "in"], ["keyword", "break"],
+ ["keyword", "case"], ["keyword", "endcase"], ["keyword", "when"],
+ ["keyword", "assign"], ["keyword", "continue"],
+ ["keyword", "limit"], ["keyword", "offset"], ["keyword", "range"], ["keyword", "reversed"],
+ ["keyword", "raw"], ["keyword", "endraw"],
+ ["keyword", "capture"], ["keyword", "endcapture"],
+ ["keyword", "tablerow"], ["keyword", "endtablerow"]
+]
+
+----------------------------------------------------
+
+Checks for all keywords.
\ No newline at end of file
diff --git a/tests/languages/liquid/number_feature.test b/tests/languages/liquid/number_feature.test
new file mode 100644
index 0000000..b88f082
--- /dev/null
+++ b/tests/languages/liquid/number_feature.test
@@ -0,0 +1,27 @@
+0b11110000
+0xBadFace
+0x1.8p1
+0xa.fp-2
+42
+42d
+1.2e3f
+0.1E-4f
+0.2e+1f
+
+----------------------------------------------------
+
+[
+ ["number", "0b11110000"],
+ ["number", "0xBadFace"],
+ ["number", "0x1.8p1"],
+ ["number", "0xa.fp-2"],
+ ["number", "42"],
+ ["number", "42d"],
+ ["number", "1.2e3f"],
+ ["number", "0.1E-4f"],
+ ["number", "0.2e+1f"]
+]
+
+----------------------------------------------------
+
+Checks for binary, hexadecimal and decimal numbers.
\ No newline at end of file
diff --git a/tests/languages/liquid/operator_feature.test b/tests/languages/liquid/operator_feature.test
new file mode 100644
index 0000000..87f4906
--- /dev/null
+++ b/tests/languages/liquid/operator_feature.test
@@ -0,0 +1,33 @@
++ ++ +=
+- -- -=
+! !=
+< << <= <<=
+> >> >>> >= >>= >>>=
+= ==
+& && &=
+| || |=
+? : ~
+* *=
+/ /=
+% %=
+
+----------------------------------------------------
+
+[
+ ["operator", "+"], ["operator", "++"], ["operator", "+="],
+ ["operator", "-"], ["operator", "--"], ["operator", "-="],
+ ["operator", "!"], ["operator", "!="],
+ ["operator", "<"], ["operator", "<<"], ["operator", "<="], ["operator", "<<="],
+ ["operator", ">"], ["operator", ">>"], ["operator", ">>>"], ["operator", ">="], ["operator", ">>="], ["operator", ">>>="],
+ ["operator", "="], ["operator", "=="],
+ ["operator", "&"], ["operator", "&&"], ["operator", "&="],
+ ["operator", "|"], ["operator", "||"], ["operator", "|="],
+ ["operator", "?"], ["operator", ":"], ["operator", "~"],
+ ["operator", "*"], ["operator", "*="],
+ ["operator", "/"], ["operator", "/="],
+ ["operator", "%"], ["operator", "%="]
+]
+
+----------------------------------------------------
+
+Checks for all operators.
\ No newline at end of file