gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:47:03 28 4
gpt4 key购买 nike

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

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

<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 不合适。

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

如何编辑 HTML.tmLanguage包括我的 <aui:script />标签库?

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

最佳答案

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

{
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>

关于javascript - 如何在 tmLanguage 文件中添加另一个要解析为嵌入式 JS 的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7693272/

28 4 0