Zlerp
Zlerp

Reputation: 467

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

Upvotes: 4

Views: 2395

Answers (4)

Andrew Zhilin
Andrew Zhilin

Reputation: 1708

Jetbrains added support for permanent language references using annotations. Here is sample from PhpStorm for PHP (pretty sure, that something similar you should have for your language as well)

enter image description here

After that string will be nicely formatted

enter image description here

Upvotes: 0

y2k-shubham
y2k-shubham

Reputation: 11607

  • At my org we use a custom .amg filetype for an internal framework that is essentially just a JSON
  • I made IntelliJ treat those as JSONs by adding *.amg pattern under Recognized File Types > JSON

enter image description here

reference: JetBrains / File type associations

Upvotes: 0

LazyOne
LazyOne

Reputation: 165088

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

Upvotes: 7

lena
lena

Reputation: 93728

You can inject JSON in your {% schema %} block manually via Alt+Enter, Inject language or reference > JSON:

enter image description here

See also https://blog.jetbrains.com/phpstorm/2017/12/twig-handling-improvements/

Upvotes: 1

Related Questions