-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Basic Syntax Highlighting for Liquid #1326
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use tabs instead of spaces to indent this file. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
comment endcomment | ||
if else elsif endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we should test the full list, here. |
||
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"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please indent this line with a tab. |
||
["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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move it above
livescript
to keep the alphabetical order please?