Sublime Forum

Better restructed text coloring?

#1

HI,

The default reST text handler seems to only color links. To make restructured text more readabale in source code format does there exist any plug-ins to colorize

  • Different heading

  • Code blocks

etc.

0 Likes

#2

Syntax highlighting depends on two things:

  • a tmLanguage file to describe the syntax
  • a tmTheme file to color said syntax.

Generally, what you want to do is to identify the scope you want to color (use Ctrl+Shift+Alt+P and look in the status bar or install a plugin like ScopeHunter) and then add some appropriate code in whatever tmTheme you are using like so:

		<dict>
			<key>name</key>
			<string>ReStrucredText: Heading</string>
			<key>scope</key>
			<string>markup.heading.restructuredtext</string>
			<key>settings</key>
			<dict>
				<key>foreground</key>
				<string>#f0f</string>
			</dict>
		</dict>

However. I had a quick look and, as is the case with Markdown, the ReStructeredText syntax that comes bundled with Sublime is a little strange (to be polite). For example, the scope “markup.heading.restructuredtext” does not identify the heading (as one would think) but the dashes/equal signs underneath it. You can therefore color the dashes but not the actual text of the heading! Grrr.

That’s the gist of it.

You also mention code blocks. Did you mean highlighting the code inside a code block?

0 Likes

#3

[quote=“quodlibet”]Syntax highlighting depends on two things:
That’s the gist of it.

You also mention code blocks. Did you mean highlighting the code inside a code block?[/quote]

Yep I was thinking that in blocks like this

The following code is magic::

       var magic = $("magic")

Poof.

The intended block would be colored with different shade of gray to enhance readability.

This could apply for all blocks, not just code blocks.

0 Likes

#4

Might be because it processes data line by line and cannot peak in the future? But coloring the heading dashes, as if it could be done by heading nesting level, would improve the readability a lot.

Just fishing around: would there be any third party solutions for this?

0 Likes

#5

To color the background of code blocks you would add something like this to your tmTheme:

      <dict>
         <key>name</key>
         <string>ReStructuredText: Code Block</string>
         <key>scope</key>
         <string>meta.raw.block.restructuredtext</string>
         <key>settings</key>
         <dict>
            <key>background</key>
            <string>#cccccc</string>
         </dict>
      </dict>

You can instead use the scope “markup.raw.restructuredtext” to change the background of all code (both blocks and inline). You may also cut the scope short to “markup.raw” which would also apply for code in Markdown and other markup syntaxes. I hope this gives you some sense of how to go about modifying your tmTheme.

As for the headings . . . the tmLanguage files are based on regular expressions so it seems to me that you are looking for should be possible. I have similar issues with the Markdown syntax but my regex-fu is quite weak :frowning:

0 Likes

#6

Try the code directive:

.. code:: python

    print "Hello World"
0 Likes

#7

How can I subscribe to answers here?

0 Likes