Search code examples
jsonintellij-ideawebstormsyntax-highlightingliquid

Adding JSON syntax highlighting to IntelliJ IDEA for .liquid files


I have been able to add syntax highlighting to my .liquid files by following the instructions here: Enabling Liquid templating syntax highlight in webStorm/phpStorm

It worked fine for my HTML and liquid syntax highlighting as it's so similar to Twig.

But my issue is I also have my schema included in each of my .liquid templates. The schema is JSON but there's not syntax highlighting on it at all.

Is there a way to add a custom syntax highlighting for a file type if it's wrapped in some sort of delimiter?

My schema is wrapped like so:

{% schema %}
  JSON object with my settings/configuration
{% endschema %}

See image below: enter image description here


Solution

  • As @yole have said: you cannot do that. Well... permanently.

    You can always inject JSON there manually .. and it will last for a while (a session for sure).

    Just place caret just after {% schema %} and hit Alt + Enter.

    enter image description here

    Choose Inject language or reference and locate JSON in the list (speed search works there as well, so just start typing).

    enter image description here

    Result is obvious:

    enter image description here


    You are using Twig plugin for .liquid files (native support for them (RUBY-7210) does not seem to be on JetBrains short list right now).

    It's now possible to have permanent Language Injection in custom Twig tag (using Twig plugin). See the screenshot below for custom injection rule that you can create yourself:

    enter image description here