Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 recognize underscore templates as HTML

So, i'm using underscore.js templates, in which i have to put my html template inside a script tag, like this

<script id="contactTemplate" type="text/template">     <img src="{{ photo }}" alt="{{ name }}" />     <h1>{{ name }}<span>{{ type }}</span></h1>     <div>{{ address }}</div>     <dl>         <dt>Tel:</dt><dd>{{ tel }}</dd>         <dt>Email:</dt><dd><a href="mailto:{{ email }}">{{ email }}</a></dd>     </dl> </script> 

but sublime text 2 is evaluating the code inside as regular js, how can i change that?

Thanks in advance!

like image 214
Rogerio Chaves Avatar asked Mar 11 '12 12:03

Rogerio Chaves


1 Answers

  1. Go to "Browse Packages" in the menu (where the menu item is depends on your platform).
  2. Open up HTML/HTML.tmLanguage
  3. Change this line (line 286 in my HTML.tmLanguage):

    <string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string>

    to this:

    <string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)(?!.*type=["']text/template['"])</string>

Now any script tags with type="text/template" or type='text/template' will render as html and not javascript.

like image 122
Matt York Avatar answered Sep 28 '22 03:09

Matt York