Sublime Forum

How to nest two scopes in .tmLanguage?

#1

I’m trying to convert this new definition (a # followed by text, some of which might be wrapped in *) into the tmLanguage format, but I can’t figure out how to do it:

contexts:
  main:
    - match: '^#+' # headers
      push:
        - meta_scope: entity.name.function
        - include: bold
        - match: $\n?  # \n is matched to render the remainder of the line in background color
          pop: true
    - include: bold
    - match: (#).*$\n? # regular comments
      scope: comment.line.number-sign.r

  bold:
    - match: \*
      push:
        - meta_content_scope: keyword.bold
        - match: \*
          pop: true

So far, I have :

   <dict>
        <key>match</key>
        <string>(#) .*$\n?</string>
        <key>name</key>
        <string>comment.line.number-sign.rmd</string>
        <key>captures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.comment.rmd</string>
            </dict>
        </dict>
    </dict>
    <dict>
        <key>match</key>
        <string>\*[^*]+\*</string>
        <key>name</key>
        <string>keyword.rmd</string>
    </dict>

However, it doesn’t work.

0 Likes

#2

Never mind, I got it to work!

 <dict>
  <key>begin</key>
  <string>(#) .*</string>
  <key>name</key>
  <string>comment.line.number-sign.rmd</string>
  <key>captures</key>
  <dict>
      <key>1</key>
      <dict>
          <key>name</key>
          <string>punctuation.definition.comment.rmd</string>
      </dict>
      <key>0</key>
      <dict>
          <key>patterns</key>
          <array>
            <dict>
              <key>name</key>
              <string>keyword.rmd</string>
              <key>match</key>
              <string>\*[^*]+\*</string>
            </dict>
          </array>
      </dict>
  </dict>
  <key>end</key>
  <string>$\n?</string>
0 Likes