Sublime text html file with built-in coffeescript

How do I get the ST3 HTML package (inline, I believe, in ST3) to recognize the inline CoffeeScript tag <script>?

those. using

    <script src="../tools/coffee-script.js"></script>
    <script type="text/coffeescript">
        ... CS code ..
    </script>

the HTML package should use the CoffeeScript package for editing in the script block (which was compiled by the coffee- script.js library when the page loads)

Any decisions on how to have an HTML package will recognize CoffeeScript just like JavaScript?

+3
source share
1 answer

You can create your own .tmLanguage (or edit an existing HTML file) that defines "text / coffeescript" to have a coffescript scope.

You can find an example 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>

.

0

All Articles