Code-to-RsT: generating syntax highlighting?

22 views
Skip to first unread message

wgw

unread,
Jul 6, 2011, 11:16:46 AM7/6/11
to leo-e...@googlegroups.com
AFAIK, the code-to-rst function does not (cannot?) generate code syntax highlighting.

Is there any easy way to do the same thing as code-to-rst but with syntax highlighting?

I know Leo does syntax highlighting, but can docutils do it during code-to-rst? (maybe this algorithm would do the trick: http://code.activestate.com/recipes/252170-syntax-highlighted-code-blocks-for-docutils/)

Edward K. Ream

unread,
Jul 6, 2011, 11:33:47 AM7/6/11
to leo-e...@googlegroups.com

Leo, that is, docutils, will use the SilverCity syntax highlighter if
it is available. However, I'm not sure whether this is works with
code-to-rst, but looking at the code I think it might.

BTW, it looks like there is no real documentation for code-to-rst.
There is mention of options for code-to-rst at
http://webpages.charter.net/edreamleo/rstplugin3.html, but that's all.

Edward

Edward

wgw

unread,
Jul 6, 2011, 11:59:47 AM7/6/11
to leo-e...@googlegroups.com
I have SilverCity installed (pip install silvercity) and since Leo uses it (doesn't it? Or is that pygments?), it must be available to docutils. But  I don't get any highlighting with code-to-rst.

When I look at the code-to-rst code, I don't see any mention of SilverCity. But maybe it is triggered implicitly.

There is no highlighting the preview pane either. In the body pane I do get proper highlighting (even with language=rest) but in the preview pane I don't. Here is my test node, where there is code highlighting in the body pane, but not in the rendered pane:

@language=rest

#####
Title
#####

::
   
    print "e"
 

wgw

unread,
Jul 6, 2011, 1:44:29 PM7/6/11
to leo-e...@googlegroups.com
(I think I am going off into a wish list here, so feel free to ignore!)

The other thing that code-to-rst does not do is interpret @doc parts as rst. I would be difficult to code # comments as rst, but the @docs could be easily interpreted as such. (This would bring us considerably closer to literate programming in a snap...)

wgw

unread,
Jul 6, 2011, 2:12:31 PM7/6/11
to leo-e...@googlegroups.com
Ok, sorry, found out how to do this... but is there a rst/Leo option for this? (did not find showDocsAsParagraphs in myLeoSettings...)

I modified the rst code in LeoRef.py:

    showDocsAsParagraphs = True #self.getOption('show_doc_parts_as_paragraphs')
    g.es("Bill's klutzy fix for setting show_doc_parts_as_paragraphs to true")

Edward K. Ream

unread,
Jul 8, 2011, 10:44:08 AM7/8/11
to leo-e...@googlegroups.com
On Wed, Jul 6, 2011 at 1:12 PM, wgw <wgwi...@gmail.com> wrote:
> Ok, sorry, found out how to do this... but is there a rst/Leo option for
> this? (did not find showDocsAsParagraphs in myLeoSettings...)

Iirc, none of the code_mode settings are in leoDocs.leo because
code_mode is a bit of an Easter egg. You can put

@bool show_doc_parts_as_paragraphs = True

in your myLeoSettings.leo. BTW, "-" and "_" get removed from the
settings name automatically, which is why print-settings reports
showDocsAsParagraphs.

EKR

Reply all
Reply to author
Forward
0 new messages