Skip to content

Commit

Permalink
fix: Improves Liquid Support (#5098)
Browse files Browse the repository at this point in the history
* Improve liquid grammar support

Brings support for Shopify Liquid Variation embedded code blocks which include:

- {% schema %}
- {% javascript %}
- {% style %}
- {% stylesheet %}

In addition, line comment highlighting is now provided.

* Include the additional modes

* add additional context and syntax samples

* purge the mode test file (not really relevant anymore)

* align behaviour for delimiter matches

* fix lookbehind expressions

* restore test for liquid mode

---------

Co-authored-by: nightwing <[email protected]>
  • Loading branch information
panoply and nightwing authored Mar 28, 2023
1 parent 38a1844 commit 0ae8dbb
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 284 deletions.
57 changes: 54 additions & 3 deletions demo/kitchen-sink/docs/liquid.liquid
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
The following examples can be found in full at http://liquidmarkup.org/
There are a couple of different Liquid variations in circulation. This grammars supports
both the Standard and Shopify Liquid variations. The following examples can be found in full at:

Standard Variation: https://shopify.github.io/liquid
Shopify Variation: https://shopify.dev/docs/api/liquid

Liquid is an extraction from the e-commerce system Shopify.
Shopify powers many thousands of e-commerce stores which all call for unique designs.
Expand Down Expand Up @@ -37,11 +41,18 @@ Some more features include:

<h2>If</h2>
<p>
{% if user.name == 'tobi' or user.name == 'marc' %}
{% if user.name == 'tobi' or user.name == 'marc' %}
hi marc or tobi
{% endif %}
</p>

<h2>Comments</h2>

{% # Line Comment %}

{% comment %}
Block Comment
{% endcomment %}

<h2>Case</h2>
<p>
Expand All @@ -58,7 +69,7 @@ Some more features include:

<h2>For Loops</h2>
<p>
{% for item in array %}
{% for item in array %}
{{ item }}
{% endfor %}
</p>
Expand All @@ -74,3 +85,43 @@ Some more features include:
{% endif %}
{% endtablerow %}
</p>

<h2>Embedded Code Blocks</h2>

This support Shopify Liquid variation JSON schema code blocks

{% schema %}
{
"string": "bar",
"boolean": true,
"number": 100,
"object": {
"array": [100, false, "string", {}, [] ]
}
}
{% endschema %}

This support Shopify Liquid variation Stylesheet and Style code blocks

{% style %}
.class {
font-size: 10px; /* comment */
}
{% endstyle %}

{% stylesheet %}
.class {
font-size: 10px; /* comment */
}
{% endstylesheet %}

This support Shopify Liquid variation JavaScript code blocks

{% javascript %}

function foo (param) {

return 'something' // comment
}

{% endjavascript %}
2 changes: 1 addition & 1 deletion src/mode/_test/highlight_rules_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (!fs.existsSync)
require("amd-loader");

var cwd = __dirname + "/";
var root = path.normalize(cwd + Array(5).join("../"));
var root = path.normalize(cwd + Array(4).join("../"));

function jsFileList(path, filter) {
if (!filter) filter = /_test/;
Expand Down
Loading

0 comments on commit 0ae8dbb

Please sign in to comment.