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?
EDIT: there is now a package for that, called "Vue Syntax Highlight"
Here is a way to do it:
name: HTML
to name: HTML-Vue
- match: '(<)((?i:script))\\b'
to - match: '(<)((?i:script))\\b(?![^>]*/>)(?![^>]*(?i:type.?=.?text/((?!javascript).*)))'
HTML-Vue.sublime-syntax
%AppData%\\Sublime Text 3\\Packages\\User\\HTML-Vue.sublime-syntax
)View > Syntax > Open all with current extension as… > HTML-Vue
I have the same issue as you. As a temporary workaround to enable syntax highlight for <script type="text/x-template">...</script>
:
C:\\Program Files\\Sublime Text 3\\Packages\\HTML.sublime-package
FYI I reported your issue into Sublime Forum.
Here's an approach that doesn't require a new syntax mode and is a simpler edit:
Copy the HTML.sublime-package file out of the Packages directory bundled with Sublime Text 3.
It's actually a zip file so unzip the contents into the user packages area as ..../User/Packages/HTML
.
Edit the HTML.sublime-syntax file within the HTML directory and in the script-type-decider
block change:
- match: (?i)(?=text/html(?!{{unquoted_attribute_value}})|'text/html'|"text/html")
to
- match: (?i)(?=text/html(?!{{unquoted_attribute_value}})|'text/html'|"text/html"|"text/x-template")
(Or substitute whatever template type you are using.)
Then restart Sublime Text.
Note, a drawback of this approach is that the HTML package will no longer be the latest when Sublime Text updates. So, you may want to perform these steps again periodically.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.