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?

5 comments

Thanks for your reply.

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

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

#{js}
    var thisShouldByHighlightedAsJs = "A string";
#{/js}

0

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:

#\{js\}(.*)#\{/js\}

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

(#\{js\}.*#\{/js\})



will highlight the tags and their content:
screenshot2.png

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.
screenshot3.png

0

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

Thanks so much.

0

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

0

Please sign in to leave a comment.