James Hiew
James Hiew

Reputation: 7107

Custom syntax highlighting for content of <script> elements depending on type attribute in IntelliJ IDEA

In IDEA, when editing a HTML file, the text content of <script> elements will be treated differently by the IDE according to the type attribute. For example, the text content of a <script type="text/javascript"> element is treated as Javascript and highlighted as such; similar for <script type="text/css"> and CSS, <script type="application/json"> and JSON, and others.

How can I configure a custom <script type="..."> language association?

Specifically, I want IDEA to treat the text content of script elements of type "x-shader/x-fragment" as GLSL. I have a GLSL language plugin installed, but it only highlights .glsl files. I am using IntelliJ IDEA 14.0.3.

NB: There is no Inject Language/Reference option for the content of <script> elements, unlike other HTML elements.

Upvotes: 2

Views: 812

Answers (2)

Ben
Ben

Reputation: 2523

Yole's answer is probably the best for your use case, but I actually ran into a similar issue where Intellij wasn't treating "text/babel" as "text/jsx" like I wanted.

If you don't mind moving the content of your script to another file, you could do something like this:

<script type="x-shader/x-fragment" src="your_script.glsl"></script>

Then of course you'd get the proper syntax highlighting when you edit the file.

Upvotes: 1

yole
yole

Reputation: 97148

You can't configure this, but this is trivial to fix in the GLSL plugin. In the Language class for GLSL (here), the "x-shader/x-fragment" MIME type needs to be passed as the second parameter to the base class constructor.

Upvotes: 2

Related Questions