1

我正在使用存储在<script type="text/template">元素中的 HTML 中的 Backbone 应用程序的模板,但这变得令人沮丧,因为 Sublime Text 将模板中的 HTML 着色,就好像它是 Javascript 一样。我想让编辑器将这些脚本标记视为与普通 HTML 标记相同。

我已经尝试在 HTML.tmLanguage 上修改 source.js.embedded.html 块中的正则表达式,但作为一个对正则表达式没有经验的人,我无法做到正确。

有任何想法吗?

我相信这是需要修改的 tmLanguage 文件的相关部分:

                <key>begin</key>
                <string>(?&lt;!&lt;/(?:script|SCRIPT))(&gt;)</string>
                <key>captures</key>
                <dict>
                    <key>1</key>
                    <dict>
                        <key>name</key>
                        <string>punctuation.definition.tag.html</string>
                    </dict>
                    <key>2</key>
                    <dict>
                        <key>name</key>
                        <string>entity.name.tag.script.html</string>
                    </dict>
                </dict>
                <key>end</key>
                <string>(&lt;/)((?i:script))</string>
4

1 回答 1

1

我认为您应该编辑其他值:

        <key>begin</key>
        <string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string>
        <key>beginCaptures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.tag.html</string>
            </dict>
            <key>2</key>
            <dict>
                <key>name</key>
                <string>entity.name.tag.script.html</string>
            </dict>
        </dict>

并更换(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)

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

于 2012-11-28T20:06:47.813 回答