如何在 tmLanguage 文件中添加另一个要解析为嵌入式 JS 的标签?

发布于 2024-12-08 21:26:09 字数 720 浏览 0 评论 0原文

背景故事(不是很重要,但它框架了问题)

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

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

将作为

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

问题

我希望 之间的所有代码都具有 JavaScript 语法突出显示。因此,我尝试编辑 HTML.tmLanguage 文件以包含此内容,但 Sublime Text 2 不适应。

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

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

站点注释,标签库接受各种属性,例如 useposition

Back Story (not really important but it frames the question)

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>

will be served as

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

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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2024-12-15 21:26:09

我在正则表达式规则方面遇到了很多麻烦,但我设法使用正常规则让它在某种程度上发挥作用。我应该补充一点,这是一个新的区块,以及常规的区块。

{
    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+)?(<)((?i:(aui[\:]script)))\b(?![^>]*/>)</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>(?<=</(aui[\:]script))(>)(?:\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>(?<!</(?:aui[\:]script))(>)</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>(</)((?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>(//).*?((?=</(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>\*/|(?=</(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>

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 Format

<dict>
    <key>begin</key>
    <string>(?:^\s+)?(<)((?i:(aui[\:]script)))\b(?![^>]*/>)</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>(?<=</(aui[\:]script))(>)(?:\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>(?<!</(?:aui[\:]script))(>)</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>(</)((?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>(//).*?((?=</(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>\*/|(?=</(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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文