Home Download Buy Blog Forum Support

Better restructed text coloring?

Better restructed text coloring?

Postby miohtama3 on Tue May 08, 2012 5:53 pm

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.
miohtama3
 
Posts: 33
Joined: Fri Apr 27, 2012 1:46 pm

Re: Better restructed text coloring?

Postby quodlibet on Tue May 08, 2012 9:19 pm

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:

Code: Select all
      <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?
quodlibet
 
Posts: 518
Joined: Sat Jun 18, 2011 5:53 pm

Re: Better restructed text coloring?

Postby miohtama3 on Wed May 09, 2012 8:37 pm

quodlibet wrote: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?


Yep I was thinking that in blocks like this

Code: Select all
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.
miohtama3
 
Posts: 33
Joined: Fri Apr 27, 2012 1:46 pm

Re: Better restructed text coloring?

Postby miohtama3 on Wed May 09, 2012 8:39 pm

quodlibet wrote: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.


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?
miohtama3
 
Posts: 33
Joined: Fri Apr 27, 2012 1:46 pm

Re: Better restructed text coloring?

Postby quodlibet on Wed May 09, 2012 9:23 pm

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

Code: Select all
      <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 :(
quodlibet
 
Posts: 518
Joined: Sat Jun 18, 2011 5:53 pm

Re: Better restructed text coloring?

Postby bc76ae96 on Wed Jul 11, 2012 9:32 am

Try the code directive:

Code: Select all
.. code:: python

    print "Hello World"
bc76ae96
 
Posts: 2
Joined: Wed Jul 11, 2012 9:30 am

Re: Better restructed text coloring?

Postby bc76ae96 on Wed Jul 11, 2012 9:36 am

How can I subscribe to answers here?
bc76ae96
 
Posts: 2
Joined: Wed Jul 11, 2012 9:30 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 29 guests