【问题标题】:sublime text html file with inline coffeescript带有内联咖啡脚本的崇高文本 html 文件
【发布时间】:2014-03-11 10:57:20
【问题描述】:
如何让 ST3 HTML 包(我相信是 ST3 内置)识别内联 CoffeeScript <script> 标记?
即使用时
<script src="../tools/coffee-script.js"></script>
<script type="text/coffeescript">
... CS code ..
</script>
HTML 包应该使用 CoffeeScript 包在脚本块中进行编辑(在页面加载时由 coffee-script.js 库编译)
关于如何让 HTML 包像识别 JavaScript 一样识别 CoffeeScript 的任何解决方案?
【问题讨论】:
标签:
html
coffeescript
inline
sublimetext3
【解决方案1】:
您可以创建一个自定义 .tmLanguage(或编辑现有的 HTML 文件)文件,该文件将定义“文本/咖啡脚本”的范围为咖啡脚本范围。
你可以找到一个例子here.
基本上,他们建议您将以下代码添加到您的 HTML.tmLangugage 文件中:
<dict>
<key>begin</key>
<string>(?:^\s+)?(<)((?i:script))\b(?=^>]*type *=^>]*text/coffeescript)\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>(?<=</(script|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.coffee.embedded.html</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>#tag-stuff</string>
</dict>
<dict>
<key>begin</key>
<string>(?<!</(?:script|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:script))</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.coffee</string>
</dict>
</array>
</dict>
</array>
</dict>
应该没问题。