Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax Highlighting for HTML inside x-template script tags in Sublime Text 3

I recently upgraded to the newest build of sublime text (Version 3.1.1 Build 3176) and have lost syntax highlighting for html contained inside tags.

For context, I'm using scripts of type x-template to create Vue.js components inside a file saved with a .html extension.

My file looks something like this:

<!-- comp.html -->
<script type="text/x-template" id="comp-template">
    <div id="comp-template>
        <h2> {{ componentTitle }} </h2>

    </div>
</script>

Previous versions of Sublime Text highlighted the html within those script tags by default, but now it no longer seems to be working. What is the best way to get sublime to once again recognize the HTML within the x-template script tags?

like image 545
elti Avatar asked May 22 '18 20:05

elti


2 Answers

EDIT: there is now a package for that, called "Vue Syntax Highlight"


Here is a way to do it:

  1. Download the HTML.sublime-syntax from Sublime Github repository: https://raw.githubusercontent.com/sublimehq/Packages/f10135941f5aeaa3af5906850f7dc296e51b1172/HTML/HTML.sublime-syntax
  2. Change line 3 from name: HTML to name: HTML-Vue
  3. Change line 83 from : - match: '(<)((?i:script))\b' to - match: '(<)((?i:script))\b(?![^>]*/>)(?![^>]*(?i:type.?=.?text/((?!javascript).*)))'
  4. Rename the file to HTML-Vue.sublime-syntax
  5. Save the file to user local settings (for Windows it's %AppData%\Sublime Text 3\Packages\User\HTML-Vue.sublime-syntax)
  6. Restart SublimeText and select View > Syntax > Open all with current extension as… > HTML-Vue
like image 181
AymKdn Avatar answered Oct 13 '22 01:10

AymKdn


I have the same issue as you. As a temporary workaround to enable syntax highlight for <script type="text/x-template">...</script>:

  1. Install an older version, for example Build 3143 (Windows: https://download.sublimetext.com/Sublime Text Build 3143 x64 Setup.exe)
  2. Backup C:\Program Files\Sublime Text 3\Packages\HTML.sublime-package
  3. Update to the latest version
  4. Restore the backup

FYI I reported your issue into Sublime Forum.

like image 33
Viliam Pucik Avatar answered Oct 13 '22 02:10

Viliam Pucik