language-liquid-redux Made for Pulsar!

Tree-sitter–based language support for Liquid templates in Pulsar

savetheclocktower

2

0

0.0.2

MIT

GitHub

language-liquid-redux

Tree-sitter–based language support for Liquid templates in Pulsar.

Features

Grammars

Other grammars can be made; use tree-sitter-liquid as the base parser, then set up in injection for whatever kind of content you want to use with Liquid. See grammars/*.cson and lib/main.js for guidance.

Custom tags

There is a major caveat here: the tree-sitter-liquid parser powering this language bundle knows a lot about built-in “paired” tags. That means stuff like {% for %}/{% endfor %}, {% capture %}/{% endcapture %}, and so on. That’s how we can do proper indentation hinting and folding for those blocks.

There are also plenty of “unpaired” tags built into Liquid — render, elsif, when, etc. For these tags, there is no corresponding ending tag. Some of these still have indentation hinting and code folding within their context and some don’t. We know which is which because they’re built into the language.

But various tools enable custom tags of both paired and unpaired varieties within Liquid. In Eleventy, for instance, you can define shortcodes that are either unpaired and function as macros… or paired and function as macros that can contain arbitrary content.

{% wat 'foo', 1, 2, 3 %}

{% narf 1, 2, 3 %}
{% endnarf %}

When the parser sees {% wat 1, 2, 3 %}, it has no clue whether there will be a corresponding {% endwat %} later in the document. A parser like tree-sitter-html can handle this situation because it knows ahead of time which tags are self-closing and which are not; we don’t enjoy that luxury.

Therefore: custom tags are supported, but they are all treated as unpaired directives. On the parser level, there is no formal relationship between {% narf 1, 2, 3 %} and {% endnarf %} the way there is between {% capture foo %} and {% endcapture %}. Hence you won’t get indentation hinting or code folding on custom paired tags. Sorry!

Snippets and other conveniences