如何获得 ST3 HTML 包(我相信是 ST3 内置的)来识别内联 CoffeeScript <script>
标签?
即使用时
<script src="../tools/coffee-script.js"></script>
<script type="text/coffeescript">
... CS code ..
</script>
HTML 包应该使用 CoffeeScript 包在脚本 block 中进行编辑(由页面加载时的 coffee-script.js 库编译)
关于如何让 HTML 包像识别 JavaScript 一样识别 CoffeeScript 的任何解决方案?
最佳答案
您可以创建自定义 .tmLanguage(或编辑现有的 HTML 文件)文件,该文件将定义“text/coffeescript”以具有 coffeescript 范围的范围。
你可以找到一个例子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>
那应该没问题。
关于html - 带有内联 coffeescript 的 sublime 文本 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21739418/