I've only been using Leo for a few days, and spent most of today figuring out how to get the new Viewrendered2 plugin to use stylesheets while displaying reStructuredText (and Markdown) nodes. So here's a brief summary to make this easier for others.
As far as prerequisites go for using reStructuredText I suggest you just use "easy_install -U Sphinx" to get Sphinx (
http://sphinx-doc.org/), since it not only installs Sphinx but its dependencies: Jinja2, docutils, and Pygments. In any case, you'll need at least:
* docutils (
https://pypi.python.org/pypi/docutils/0.11)
* pygments (
http://pygments.org/)
The new viewrendered2 plugin only works with the latest version of Leo on github. It doesn't work with Leo 4.11 Final. The only way I could get the viewerendered2 plugin to work was to change the Global Settings (leoSettings.leo) --- something the documentation recommends you **not** do. In the @enabled-plugins node, I commented out viewrendered.py and added viewrendered2.py.
After you restart Leo, pick a node and hit Alt+0 (zero) --- or even better right-click the splitters and chose Open Window > Viewrendered to get a free floating window that can be maximized on a second screen. You'll now see full HTML rendering just like a browser shows.
Currently, there seems to be a little bug. You have to add::
@language restto the top of a @rst node in order for more than just the first paragraph to be rendered [1]?
Unfortunately, the results are pretty dull looking. The rest of this section describes how to connect stylesheets to what is displayed in the viewrendered2 window.
First all you need to have a stylesheet. It can be pretty daunting to create a docutils compatible stylesheet from scratch so choose one of the following to get started:
*
https://bitbucket.org/cskeeters/rst2html-style Nice clean look.
*
http://docutils.sourceforge.net/sandbox/stylesheets/voidspace.css somewhat ugly but shows the possibilities?
* <pythondir>/Lib/site-packages/docutils/writers/html4css1/html4css1.css The default but boring appearance.
If you want to have colorized code blocks using pygments, you also need have styles for it. To see what the possible pygment built-in styles [2] are, at a Python prompt do::
>>> from pygments.styles import get_all_styles
>>> styles = list(get_all_styles())
>>> styles.sort()
>>> styles
['autumn', 'borland', 'bw', 'colorful', 'default', 'emacs', 'friendly', 'fruity', 'manni', 'monokai', 'murphy', 'native', 'pastie', 'perldoc', 'tango', 'trac', 'vim', 'vs']Then generate a .css file for whatever style you want to use::
pygmentize -S default -f html -a .code >pygments_default.cssNext, I suggest you create a mystyles.css file. Normally it would be in the same place as your .leo file. Inside it put, for example::
@import url(skeeterstyle.css);
@import url(pygments_default.css);
<any additional style customizations here>
I figured out how to use viewrendered2 by choosing it from the Plugins menu and reading the displayed documentation. If you scroll down, eventually you'll see the list of all the docutils related settings::
@string vr-stylesheet-path
@int vr-halt-level = 6
@string vr-math-output = mathjax
@bool vr-smart-quotes = True
@bool vr-embed_stylesheet = True
@bool vr-xml-declaration', False
(Optional) I changed my local copy of leo.plugins.viewrendered2.WebViewPlus#init_config() to add some additional docutils options::
getConfig(gc.getString, 'syntax_highlight', 'long')
getConfig(gc.getBool, 'no_compact_lists', False)
getConfig(gc.getBool, 'no_compact_field_lists', False)
I like vr-syntax-highlight [3] because the default otherwise is "long" which doesn't colorize nearly as much as "short" for some reason.
vr-no-compact-lists [4] avoids the problem where "complex" lists get inconsistent spacing between sublists [5][6]. With this option on, you can at least get exactly what you want with some additional css styling.
Finally, add the following nodes to the @setting section of your .leo document::
@string vr-stylesheet-path = mystyles.css
@string vr-syntax-highlight = short
@bool vr-no-compact-lists = True
As near as I can tell you have to close & reopen the Leo document for its new settings to be recognized?
When you reopen the Viewrendered2 window you'll now see fully styled HTML :)
Markdown support
================
Markdown is apparently only partially supported at this time.
You have to have Python-Markdown (
https://pythonhosted.org/Markdown/) installed to view Markdown as HTML.
Then create a @md node that contains Markdown syntax in its body. It's probably a bug but currently you have to specify::
@color
@language md
at the beginning of the body (or the body of a parent node?) to force it to convert Markdown to HTML?
Individual nodes are displayed correctly, but I couldn't get the Viewrendered2 Whole Tree option to display more than just the @md node titles if any parent node was selected? Of course I had::
@string target_language = rest in my @settings and was mixing reST with md this problem occurred. I didn't try pure md since I hardly ever do that.
Looking at the HTML output, the current viewrendered2 implementation only just dumps out <h1> and it contents. It doesn't bother with any <html> or <head> tags and thus doesn't specify any stylesheets. This is probably less a problem with the Markdown specific code, and more its integration with the rest of viewrendered2?
Additionally, even when viewrendered2 is fixed, the CodeHilite Markdown extension uses "codehilite" rather than just "code" as its css class. So any css file would have to use that for all the pygment's selectors like::
pygmentize -S default -f html -a .codehilite >pygments_mddefault.css In CSS, I think you can do things like::
.code .nf, .codehilite .nf { color: #0066BB; font-weight: bold } /* Name.Function */ But I don't think you can get the pygmentize script to generate this? It's probably easier to just @import the separate .css file in your mystyles.css file.
BTW, I composed this post using Leo and the viewrender2 version of it looks **much** nicer than the way it looks here on Google Groups :)
[1]
https://groups.google.com/forum/#!topic/leo-editor/l7jzwNxGN_U/TOirjtdPsRoJ[2]
http://pygments.org/docs/styles/#builtin-styles[3]
http://docutils.sourceforge.net/docs/user/config.html#syntax-highlight[4]
http://docutils.sourceforge.net/docs/user/config.html#compact-lists[5]
http://docutils.sourceforge.net/FAQ.html#how-are-lists-formatted-in-html[6]
http://sphinx-doc.org/config.html#confval-html_compact_lists