如何在Sublime Text 2中更改JSON“Key”的颜色

时间:2014-05-01 20:32:20

标签: xml json sublimetext2 syntax-highlighting

所以我补充道:

    <dict>
        <key>name</key>
        <string>JSON Key</string>
        <key>scope</key>
        <string>meta.structure.dictionary.json string2.quoted.double.json</string>
        <key>settings</key>
        <dict>
            <key>foreground</key>
            <string>#00FF00</string>
        </dict>
    </dict>

我称为custom.tmTheme的配色方案,我已添加:

    <key>string2</key>
    <dict>
        <key>begin</key>
        <string>"</string>
        <key>beginCaptures</key>
        <dict>
            <key>0</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.string2.begin.json</string>
            </dict>
        </dict>
        <key>end</key>
        <string>"\s.:</string>
        <key>endCaptures</key>
        <dict>
            <key>0</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.string2.end.json</string>
            </dict>
        </dict>
        <key>name</key>
        <string>string2.quoted.double.json</string>
        <key>patterns</key>
        <array>
            <dict>
                <key>match</key>
                <string>(?x:                # turn on extended mode
                 \\                # a literal backslash
                 (?:               # ...followed by...
                   ["\\/bfnrt]     # one of these characters
                   |               # ...or...
                   u               # a u
                   [0-9a-fA-F]{4}  # and four hex digits
                 )
               )</string>
                <key>name</key>
                <string>constant.character.escape.json</string>
            </dict>
            <dict>
                <key>match</key>
                <string>\\.</string>
                <key>name</key>
                <string>invalid.illegal.unrecognized-string-escape.json</string>
            </dict>
        </array>
    </dict>

到我的包文件夹中的JSON-test.tmLanguage文件,但我还是看不到绿键。

有谁知道我哪里出错了?

1 个答案:

答案 0 :(得分:5)

您不需要创建或修改.tmLanguage文件,您应该只需使用JavaScript -> JSON语法即可。像这样修改.tmTheme

<dict>
    <key>name</key>
    <string>JSON Key</string>
    <key>scope</key>
    <string>meta.structure.dictionary.json string.quoted.double.json -meta.structure.dictionary.value.json</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#00FF00</string>
    </dict>
</dict>

你应该全力以赴。它将突出显示JSON字典中包含的所有字符串,但如果范围包含meta.structure.dictionary.value.json则不会,因此它只会突出显示键。