Search code examples
sublimetext2syntax-highlightingtextmatevisual-studio-codetmlanguage

Textmate: All text within begin and end capture is not colored/matched


So I'm able to match/color {{#if media.isMobile}} and it's end tag {{/if}}. But everything in between the blocks is just regular text now (Before it had nice html coloring). So how do I get the content inbetween the captures to be captured using the top level of the dictionary (Since everything not within the tags still has proper color)?

Here's my language pattern code for if, incase you need

<key>if_token</key>
    <dict>
        <key>begin</key>
        <string>(\{\{#)(if) (.+)(\}\})</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>keyword.operator.handlebars</string>
            </dict>
            <key>3</key>
            <dict>
                <key>name</key>
                <string>variable.parameter.handlebars</string>
            </dict>
            <key>4</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.tag.end.html</string>
            </dict>
        </dict>
        <key>end</key>
        <string>(\{\{\/)(if)(}})</string>
        <key>endCaptures</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>keyword.operator.handlebars</string>
            </dict>
            <key>3</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.tag.end.html</string>
            </dict>               
        </dict>

    </dict>

Solution

  • Figured it out. Instead of capturing the entire block. Capture Begin: {{#if .. and End: }} as one pattern. And {{/if}} as another.