2

I installed the packages MarkdownExtended and MonokaiExtended, which gives me an already quite good highlighting for markdown files. However, being a perfectionist, I want to color the asterisks of unordered lists in markdown. The color scheme is set to Monokai Extended and I've edited that .tmTheme file under Packages/User/Color Highlighter/themes/Monokai Extended.tmTheme (careful, that's a big big text file) as follows:

    <dict>
        <key>name</key>
        <string>Markdown: List Items Punctuation</string>
        <key>scope</key>
        <string>punctuation.definition.list_item.markdown</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#404b16</string>
        </dict>
    </dict>

This seems to be exactly what I am looking for, however, the color of the asterisks doesn't change. Is there some other file or position in the file I need to edit? What did I overlook?

EDIT#1

There seems to have been some issue with my Sublime Text 3. When I opened the Monokai Extended.tmTheme the file inflated and got a hundred thousand lines. Now I opened it with another text editor and then changed the values like this:

    <dict>
        <key>name</key>
        <string>Markdown: List Items Punctuation</string>
        <key>scope</key>
        <string>punctuation.definition.list_item.markdown</string>
        <key>settings</key>
        <dict>
            <key>fontStyle</key>
            <string>bold</string>
            <key>foreground</key>
            <string>#80Ab36</string>
        </dict>
    </dict>

This results in the following behavior:

enter image description here

So the first asterisk is already colored, only missing the other ones...

Summary

  • SublimeText 3 (v3103)
  • Packages: Markdown Extended, Monokai Extended
  • Syntax Highlighting is set to Markdown Extended
  • Color Scheme is set to Monokai Extended
  • Want to color asterisks of unordered lists in markdown files

Chosen Solution

I used the code in the accepted answer, but I changed it a little bit, so that it includes indented asterisks:

list-paragraph:
- match: \G\s+(?=\S)
    push:
        - meta_scope: meta.paragraph.list.markdown
        - match: ^\s*$
            pop: true
        - match: '^([ ]{0,4}|\t{0,1})([*+-])(?=\s)'
            scope: punctuation.definition.list_item.markdown
        - match: '^([ ]{0,4}|\t{0,1})([0-9]+)(\.)(?=\s)'
            captures:
                1: punctuation.definition.list_item.markdown punctuation.definition.list_item.number.markdown
                2: punctuation.definition.list_item.markdown
        - include: inline

EDIT#2

I've now changed it again in order to allow only certain indentations to cause the color change:

list-paragraph:
- match: \G\s+(?=\S)
    push:
        - meta_scope: meta.paragraph.list.markdown
        - match: ^\s*$
            pop: true
        - match: '^([ ]{2}|[ ]{4}|[ ]{6}|[ ]{8}|[ ]{10}|[ ]{12}|\t{0,3})([*+-])(?=\s)'
            scope: punctuation.definition.list_item.markdown
        - match: '^([ ]{2}|[ ]{4}|[ ]{6}|[ ]{8}|[ ]{10}|[ ]{12}|\t{0,3})([0-9]+)(\.)(?=\s)'
            captures:
                1: punctuation.definition.list_item.markdown punctuation.definition.list_item.number.markdown
                2: punctuation.definition.list_item.markdown
        - include: inline
  • What build of ST3 are you using? Have you upgraded to 3103 yet? – MattDMo Feb 28 '16 at 21:14
  • @MattDMo Yes 3103 it is, updated my question. – Zelphir Feb 29 '16 at 2:13
  • 1
    The Q&A format reserves questions for questions and answers for solutions. Mixing them confuses things and makes it harder for people to search for answers. It would be better to put the things related to your solution (portion starting with "Chosen Solution"), in an answer. – fixer1234 Jun 24 '16 at 15:47
3

You'll need to edit the Markdown Extended syntax definition file, which is locked up in a zipped .sublime-package archive, so first you'll need to install PackageResourceViewer. Once installed, open the Command Palette and type prv to bring up the PackageResourceViewer options. Select PackageResourceViewer: Open Resource, then Markdown Extended, then Markdown Extended.sublime-syntax. The selection menu will stay open, just hit Esc to get rid of it.

In Markdown Extended.sublime-syntax, scroll down to approximately line 1172 (in the current version, it may change) to the section entitled list-paragraph. It should look like this:

list-paragraph:
  - match: \G\s+(?=\S)
    push:
      - meta_scope: meta.paragraph.list.markdown
      - match: ^\s*$
        pop: true
      - include: inline

To make it recognize multiple list items, change that section to this:

list-paragraph:
  - match: \G\s+(?=\S)
    push:
      - meta_scope: meta.paragraph.list.markdown
      - match: ^\s*$
        pop: true
      - match: '^\s{0,4}([*+-])(?=\s)'
        scope: punctuation.definition.list_item.markdown
      - match: '^\s{0,4}([0-9]+)(\.)(?=\s)'
        captures:
          1: punctuation.definition.list_item.markdown punctuation.definition.list_item.number.markdown
          2: punctuation.definition.list_item.markdown
      - include: inline

Save the file (it should automatically save in the right spot), and your list items should now be highlighted appropriately.

  • Doesn't match indented items, but I think I get the idea, thanks! – Zelphir Mar 1 '16 at 18:17
  • Correction: It only doesn't match items indented further than 3 spaces or items indented by tabs. See my question for information about how to do that, by changing the code provided in this answer a little. – Zelphir Mar 1 '16 at 18:34
  • @Zelphir see my edit for a better solution. \s means any whitespace character. The problem with yours is that it creates another capture group, so in the last - match section it will actually be scoping the whitespace as the list item, not the */+/- character or the digit(s) in a numbered list. – MattDMo Mar 1 '16 at 22:27
  • I think you're right. I did it that way because I only wanted the indentation style "2 spaces", "4 spaces" and "tab" to be causing the color. for "3 spaces" I wanted to leave it white, so that one sees that there is a different indentation. How could I do that? I think your improved solution does 0 to 4, which includes 3 and 1 spaces. – Zelphir Mar 2 '16 at 10:35

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.