Javascript syntax highlighting inside html using a custom tag (IntelliJ 11 Ultimate with Play! 1.25)

I am trying to get javascript syntax highlighting to work within an html file using a custom (Play! Framework) tag.

If I wrap my javascript in <script>...</script> tags, all is well.

When using a Play! custom tag #{js}...#{/js} to wrap my javascript, I cannot get highlightling to work.

Des anyone have any ideas?


Thanks for your reply.

I tried a language injection as follows, but this didn't work as i expected.

An example of the code (in an .html file) that I wish to highlight is:

    var thisShouldByHighlightedAsJs = "A string";


The "Tag Name" field identifies the XML tag you want to be highlighted as the selected language. So with what you have, you are asking for everything between <js> </js> to be highlighted as JavaScript. You need to identify a Regex pattern in the "Value Pattern" field in the Advanced section. The pattern must have a single capturing group. Everything in the first capturing group will get highlighted.

So the patten:


will highlight everything between the tags, but not the tags themselves:
The pattern


will highlight the tags and their content:

If you want the pattern to apply to all entries in the file, leave the "Local Name" field blank (or enter html). If you only want #{js} items in the Body to be highlighted, enter body in the "Local Name".

Here are the final settings. Tweak as desired.


Fantastic! Exactly what I was hoping for. Seeing an example, it makes perfect sense now.

Thanks so much.


Does language injection work only in html files? I'm trying to highlight javascript inside <% %> tags in Classic ASP files.


Please sign in to leave a comment.