Sublime Forum

Syntax highlight for custom <script> tag

#1

I’m using an HTML template system that uses a custom tag for inline scripts: <templater:js></templater:js>
The issue is that it’s not recognizing the JS inside it, I’d like to use the same syntax highlight functionality as the built in <script> tag.

Is this possible?

Thanks in advance

0 Likes

#2

this was also asked here but I think the answers relate to ST2:

for ST3, take a look at how the HTML syntax definition includes the JS syntax - you’ll want to modify your HTML.sublime-syntax file to match your <templater:js> just like it does for <script>

0 Likes

#3

Got it thanks :slight_smile:

Added this to my HTML.sublime-syntax

- match: '(<)((?i:templater\:js))\b(?![^>]*/>)(?![^>]*(?i:type.?=.?text/((?!javascript).*)))'
  captures:
    1: punctuation.definition.tag.begin.html
    2: entity.name.tag.script.html
  push:
    - match: (?i)(</)(templater\:js)(>)
      captures:
        1: punctuation.definition.tag.begin.html
        2: entity.name.tag.script.html
        3: punctuation.definition.tag.end.html
      pop: true
    - include: tag-stuff
    - match: '>'
      scope: punctuation.definition.tag.end.html
      push:
        - meta_content_scope: source.js.embedded.html
        - include: 'scope:source.js'
      with_prototype:
         - match: (?i)(?=</templater\:js)
           pop: true
0 Likes