Search code examples
pythonsublimetext2docstring

Can Sublime color Python docstrings differently from single-line strings?


I'd like to differentiate between Python docstrings and single-line strings in Sublime Text 2. Looking at the Python language definition, I can see this, along with a matching definition for apostrophe-strings that uses the same comment.block.python name.

<dict>
    <key>begin</key>
    <string>^\s*(?=[uU]?[rR]?""")</string>
    <key>end</key>
    <string>(?&lt;=""")</string>
    <key>name</key>
    <string>comment.block.python</string>
...

But when I create a new color rule like this:

<dict>
    <key>name</key>
    <string>Docstring</string>
    <key>scope</key>
    <string>comment.block.python</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#008800</string>
    </dict>
</dict>

Nothing happens; they remain colored the same as single-line strings.

Is it possible to do this? If so, what am I doing wrong?


Solution

  • Maybe change to:

    <dict>
        <key>name</key>
        <string>Docstring</string>
        <key>scope</key>
        <string>string.quoted.double.block.python</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#008800</string>
        </dict>
    </dict>
    

    I only tested it briefly, but it seemed to work.