I've recently started experimenting with jQuery Templates, which rely on your ability to wrap HTML within SCRIPT
tags.
<script id="movieTemplate" type="text/x-jquery-tmpl">
<li>
<b>${Name}</b> (${ReleaseYear})
</li>
</script>
The problem is, TextMate naturally assumes that anything within SCRIPT
tags is JavaScript. I'm sure it's possible to make TextMate treat the content differently based on the type
attribute, but I'm struggling with some of the grammar being used in the bundle. I'm pretty confident that the line below is key, but I'm not sure where to start.
begin = '(?:^\s+)?(<)((?i:script))\b(?![^>]*/>)';
Has anyone already dealt with a similar scenario? Would someone be able to point me in the right direction?
Rich
begin = '(?:^\s+)?(<)((?i:script))\b(?!([^>]*text/x-jquery-tmpl[^>]*|[^>]*/>))';
will stop treating script tags with "text/x-jquery-tmpl" in them as javascript
That's a regular expression. You could extend it to check for the type text/javascript
like that:
begin = '(?:^\s+)?(<)((?i:script))\b(.*?type="text/javascript")(?![^>]*/>.*)';
I have only tested it with if
, but it seems to work. When the type is text/javascript
TextMate expands it to Javascript for every other type it uses PHP. (Just like outside of script tags.)
You can read more about how TextMate uses regular expressions here: Regex (TextMate Manual)
The matching groups are meaningful. You need to change it to this:
begin = '(?:^\s+)?(<)((?i:script))\b(?:.*?type="text/javascript")(?![^>]*/>)';
In order to keep the current matching group configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With