html - 带有内联 coffeescript 的 sublime 文本 html 文件

标签 html coffeescript inline sublimetext3

如何获得 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+)?(&lt;)((?i:script))\b(?=^&gt;]*type *=^&gt;]*text/coffeescript)\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;/(script|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.coffee.embedded.html</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>#tag-stuff</string>
        </dict>
        <dict>
            <key>begin</key>
            <string>(?&lt;!&lt;/(?:script|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: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/

相关文章:

c++ - c++ 内联函数的要求

javascript - 检测 DOM 元素的内联/ block 类型

c++ - 编译器为函数指定 always_inline

html - Css - wordpress 中水平对齐期间的不可见边距

node.js - 在 npm install 上编译 CoffeeScript

javascript - 是否有等效于 SVG 的 Canvas toDataURL 方法?

jquery - 为什么 javascript "this"不能与 "each"一起使用?

node.js - 当我的咖啡文件发生变化时,如何让连接 Assets 重新编译它们?

php - 我在 Chrome 中看不到带有 onmessage 方法的 HTML5 EventSource 事件

jquery - 将初始高度设置为响应式容器 HTML/CSS