I’m trying to achieve syntax highlighting for the text in restructuredtext section headings in ST3. Here’s a link to an earlier discussion on this: Implement a better reStructuredText syntax highlighting. I’ve tried two approaches.
First, Kiwi Lorenz’s tmLanguage spec reStructuredText Improved which uses the begin/end construction with a backreference.
<key>begin</key>
<string>(?x) ^ (?= (\S+\x{00000020})* \S+ $) (?= (?!\d[\.\)]) \w .{2,55} (?<!\.|::|\\|\x{00000020}) $)</string>
<key>contentName</key>
<string>markup.heading.headline.or-term.restructuredtext</string>
<key>end</key>
<string>(?x) ^ (?=[\x{00000020}\t]+\S) | ^ ( ([=\-`:.'"~^_*+\#])\2{2,55} | \s* | (?=\|\s*$) )$</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.operator.heading.restructuredtext</string>
</dict>
</dict>
The problem using this approach is that while typing regular paragraph text (between 3 and 55 characters), the editor will switch back and forth between ‘markup.heading.headline.or-term.restructuredtext’ and
‘meta.paragraph.restructuredtext’. This is really distracting if heading and paragraph text are highlighted differently. For example, the following text, without a terminating character or space, is highlighted as a heading (bc it’s scoped as a term).
foobar
So, I thought the sublime-syntax push/pop functionality could accomplish header text highlighting, but I have been unsuccessful at modifying the default sublime restructuredtext syntax file Here so that the text in section headings is highlighted. Currently the underline is highlighted, but not the text. The relevant part of the file is the following.
- match: '(^(=|-|~|`|#|"|\^|\+|\*){3,}$){1,1}?'
scope: markup.heading.restructuredtext
captures:
1: punctuation.definition.heading.restructuredtext
Neither the provided examples in the docs nor looking through recently updated languages (e.g. Go), have helped me get there.
I would appreciate any help/suggestions for how to implement this. I’m open to using either tmLanguage or sublime-syntax.
Thanks,
CL