SublimeText / BetterCoffeeScript

Syntax highlighting and checking, commands, shortcuts, snippets, watched compilation and more.
437 stars 64 forks source link

Recognize embedded CoffeeScript in HTML <script type='text/coffeescript'> tags #207

Open Nieralyte opened 9 years ago

Nieralyte commented 9 years ago

alright. i did the following modifications to the HTML.tmLanguage file which is located in a compressed archive C:\ProgramFiles\SublimeText3\Packages\HTML.sublime-package (or similar path):

i replaced:

<string>(?:^\s+)?(&lt;)((?i:script))\b(?![^&gt;]*/&gt;)</string>

...with:

<string>(?:^\s+)?(&lt;)((?i:script))\b(?=[^&gt;]*type *=[^&gt;]*text/javascript)\b(?![^&gt;]*/&gt;)</string>

(so embedding regular javascript works with <script type='text/javascript'> tag)

and added:

<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.begin.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.begin.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>

(so embedding coffeescript works with <script type='text/coffeescript'> tag)

P.S. based on http://www.sublimetext.com/forum/viewtopic.php?f=2&t=5800&p=37751#p37751