崇高着色括号之间的所有颜色与外面不同的颜色

Sublime coloring everything between brackets different color than outside

在 Sublime Syntax 文件中,我可以使用如下命令为所有硬括号和内部的所有内容着色:

- match: '\[.*?\]'
  scope: keyword.control  

如果我想给括号内的所有东西涂上不同的颜色,我试过这样的方法:

- match: '\['
  scope: variable.function
  comment: Images
  push:
    - meta_scope: constant.numeric
    - match: \]
      pop: true

问题是它会将最后一个支架着色为与内部相同的颜色。知道如何使最后一个括号与起始括号颜色相同吗?

Syntax documentation 中,它这样说(强调我的):

  • meta_scope. This assigns the given scope to all text within this context, including the patterns that push the context onto the stack and pop it off.
  • meta_content_scope. As above, but does not apply to the text that triggers the context (e.g., in the above string example, the content scope would not get applied to the quote characters).

在您的第二个示例中,您使用的是 meta_scope,这会导致将上下文弹出堆栈的匹配项也应用此范围。如果将它换成 meta_content_scope,则不会发生这种情况。然而,在那种情况下,根本没有特定范围应用于 ] 字符,因此它看起来与标准文本颜色相同。

为了解决这个问题,您还可以对它应用与最初推送上下文的范围相同的范围。例如:

- match: '\['
  scope: variable.function
  comment: Images
  push:
    - meta_content_scope: constant.numeric
    - match: \]
      scope: variable.function
      pop: true

从技术上讲,如果您所追求的只是颜色,则只需要 scope 并且可能会满足您的要求。然而,"cleaner" 也使用 meta_content_scope,以避免它可能仍然根据错误的范围着色的可能性。