如何在 tmLanguage 文件中添加另一个要解析为嵌入式 JS 的标签? [英] How do I add another tag to be parsed as embedded JS in a tmLanguage file?

查看:42
本文介绍了如何在 tmLanguage 文件中添加另一个要解析为嵌入式 JS 的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 JSP 中有一个 TagLib,它获取其内容并将其包含的代码包装在一个脚本块中(它做的更多,但就问题而言,这并不重要).例如:

I have a TagLib in a JSP that takes its contents and wraps its containing code in a script block (it does much more but for the sake of the question it is not important). For example:

<aui:script use="some-module">
    //my code
</aui:script>

将作为

<script type="text/javascript>
    AUI().use('sub-module', function(A) {
        // my code
    }
</script>

问题

我希望 <aui:script use="things"></aui:script> 之间的所有代码都具有 JavaScript 语法突出显示.因此,我尝试编辑 HTML.tmLanguage 文件以包含此内容,但 Sublime Text 2 不合适.

The Question

I would like all the code in between <aui:script use="things"></aui:script> and to have JavaScript syntax highlighting. So I tried editing the HTML.tmLanguage file to include this but Sublime Text 2 throws a fit.

不可否认,我的正则表达式知识很差.

Admittedly my regex knowledge is poor.

如何编辑 HTML.tmLanguage 以包含我的 标签库?

How can I edit HTML.tmLanguage to include my <aui:script /> taglib?

站点注意,taglib 接受各种属性,例如 useposition.

Site note, the taglib accepts various attributes like use and position.

推荐答案

我在使用正则表达式规则时遇到了很多麻烦,但我设法使用普通规则让它在某种程度上起作用.我应该补充一点,这是一个新块,以及常规块.

I have so much trouble with the regex rules but I managed to get it somewhat working using the normal rules. I should add that this is a new block, along with the regular one.

{
    name = 'source.js.embedded.html';
    begin = '(?:^\s+)?(<)((?i:(aui[\:]script)))\b(?![^>]*/>)';
    end = '(?<=</(aui[\:]script))(>)(?:\s*\n)?';
    beginCaptures = {
        1 = { name = 'punctuation.definition.tag.html'; };
        2 = { name = 'entity.name.tag.script.html'; };
    };
    endCaptures = {
        2 = {
            name = 'punctuation.definition.tag.html';
        };
    };
    patterns = (
        {
            include = '#tag-stuff';
        },
        {
            begin = '(?<!</(?:aui[\:]script))(>)';
            end = '(</)((?i:aui[\:]script))';
            captures = {
                1 = {
                    name = 'punctuation.definition.tag.html';
                };
                2 = {
                    name = 'entity.name.tag.script.html';
                };
            };
            patterns = (
                {   name = 'comment.line.double-slash.js';
                    match = '(//).*?((?=</(aui[\:]script))|$\n?)';
                    captures = {
                        1 = {
                            name = 'punctuation.definition.comment.js';
                        };
                    };
                },
                {
                    name = 'comment.block.js';
                    begin = '/\*';
                    end = '\*/|(?=</(aui[\:]script))';
                    captures = {
                        0 = {
                            name = 'punctuation.definition.comment.js';
                        };
                    };
                },
                {
                    include = '#php';
                },
                {
                    include = 'source.js';
                },
            );
        },
    );
}

XML 格式

<dict>
    <key>begin</key>
    <string>(?:^\s+)?(&lt;)((?i:(aui[\:]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>
    <key>end</key>
    <string>(?&lt;=&lt;/(aui[\:]script))(&gt;)(?:\s*\n)?</string>
    <key>endCaptures</key>
    <dict>
        <key>2</key>
        <dict>
            <key>name</key>
            <string>punctuation.definition.tag.html</string>
        </dict>
    </dict>
    <key>name</key>
    <string>source.js.embedded.html</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>#tag-stuff</string>
        </dict>
        <dict>
            <key>begin</key>
            <string>(?&lt;!&lt;/(?:aui[\:]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:aui[\:]script))</string>
            <key>patterns</key>
            <array>
                <dict>
                    <key>captures</key>
                    <dict>
                        <key>1</key>
                        <dict>
                            <key>name</key>
                            <string>punctuation.definition.comment.js</string>
                        </dict>
                    </dict>
                    <key>match</key>
                    <string>(//).*?((?=&lt;/(aui[\:]script))|$\n?)</string>
                    <key>name</key>
                    <string>comment.line.double-slash.js</string>
                </dict>
                <dict>
                    <key>begin</key>
                    <string>/\*</string>
                    <key>captures</key>
                    <dict>
                        <key>0</key>
                        <dict>
                            <key>name</key>
                            <string>punctuation.definition.comment.js</string>
                        </dict>
                    </dict>
                    <key>end</key>
                    <string>\*/|(?=&lt;/(aui[\:]script))</string>
                    <key>name</key>
                    <string>comment.block.js</string>
                </dict>
                <dict>
                    <key>include</key>
                    <string>#php</string>
                </dict>
                <dict>
                    <key>include</key>
                    <string>source.js</string>
                </dict>
            </array>
        </dict>
    </array>
</dict>

这篇关于如何在 tmLanguage 文件中添加另一个要解析为嵌入式 JS 的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆