开发者

Amend HTML Grammar based on attributes in TextMate

开发者 https://www.devze.com 2023-02-23 05:34 出处:网络
I\'ve recently started experimenting with jQuery Templates, which rely on your ability to wrap HTML within SCRIPT tags.

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 nat开发者_如何学Curally 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消