Sublime Forum

Custom <script> tag in HTML file

#1

I frequently use HTML templates within

How can I transform a tag with a specific “type” attribute into showing the HTML syntax (and HTML snippets), instead of treating it like a JavaScript tag?

0 Likes

Syntax highlight for custom <script> tag
#2

I believe you will need to edit the HTML grammar (tmLanguage) file and add additional scopes to do this. Unfortunately I’m not familiar enough with this to offer more details though I’m sure someone else can.

0 Likes

#3

Thanks!

I checked the file you recommended and, basically, commented out what I thought was relevant, and it worked.

0 Likes

#4

kendagriff, can you post exactly what did?

thanks ahead

0 Likes

#5

If anyone still wonders, you can compare this to your HTML tmlanguage file,

pastebin.com/irTLDzKC

You basically just comment out 284-381ish. I don’t use inline JS so didn’t both to have them check for “type” attribute which would be true fix for these client side templates.

0 Likes

#6

Nice! Gonna give that a shot… would be cool if there was a less ‘hacky’ way of doing this.

0 Likes

#7

This solution is almost ideal, except that it disallows inline javascript.

I’m hoping to find a solution that allows inline javascript, inline handlebars templates, and proper syntax coloring for each.

Seems like the way to accomplish this might be to edit the regex in line 286 such that it excludes any script that with an opening tag that contains type=“text/x-handlebars-template”.

Does anyone know how to do that?

0 Likes

#8

[quote=“Kirkman”]This solution is almost ideal, except that it disallows inline javascript.

I’m hoping to find a solution that allows inline javascript, inline handlebars templates, and proper syntax coloring for each.

Seems like the way to accomplish this might be to edit the regex in line 286 such that it excludes any script that with an opening tag that contains type=“text/x-handlebars-template”.

Does anyone know how to do that?[/quote]

I did something similar with graphviz. Don’t want to retype the explanation, so I’ll link you to the StackOverflow where I did already :smile: They wanted to highlight embedded html in an AngularJS directive, but what they wanted is the same.

The short version is I think it’s possible, you would just have to create the appropriate begin regex as you had mentioned and include the appropriate source.

stackoverflow.com/questions/1543 … 2#15441612

0 Likes

#9

Here is how i did it:
Edit HTML.tmLanguage and do the following change: gist.github.com/iamntz/5070840

You can change text/template to whatever you would like (text/handlebar or whatever). This will NOT affect normal javascript highlight.

0 Likes

#10

That worked iamntz. Many thanks.

0 Likes