Version

Quick search

reStructuredText renderer

New in version 1.1.0.

reStructuredText is an easy-to-read, what-you-see-is-what-you-get plaintext markup syntax and parser system.

Note

This widget requires the docutils package to run. Install it with pip or include it as one of your deployment requirements.

Warning

This widget is highly experimental. The styling and implementation should not be considered stable until this warning has been removed.

Usage with Text

text = """
.. _top:

Hello world
===========

This is an **emphased text**, some ``interpreted text``.
And this is a reference to top_::

    $ print("Hello world")

"""
document = RstDocument(text=text)

The rendering will output:

_images/rstdocument.png

Usage with Source

You can also render a rst file using the source property:

document = RstDocument(source='index.rst')

You can reference other documents using the role :doc:. For example, in the document index.rst you can write:

Go to my next document: :doc:`moreinfo.rst`

It will generate a link that, when clicked, opens the moreinfo.rst document.

class kivy.uix.rst.RstDocument(**kwargs)

Bases: kivy.uix.scrollview.ScrollView

Base widget used to store an Rst document. See module documentation for more information.

goto(ref, *largs)

Scroll to the reference. If it’s not found, nothing will be done.

For this text:

.. _myref:

This is something I always wanted.

You can do:

from kivy.clock import Clock
from functools import partial

doc = RstDocument(...)
Clock.schedule_once(partial(doc.goto, 'myref'), 0.1)

Note

It is preferable to delay the call of the goto if you just loaded the document because the layout might not be finished or the size of the RstDocument has not yet been determined. In either case, the calculation of the scrolling would be wrong.

You can, however, do a direct call if the document is already loaded.

New in version 1.3.0.

preload(filename, encoding='utf-8', errors='strict')

Preload a rst file to get its toctree and its title.

The result will be stored in toctrees with the filename as key.

render()

Force document rendering.

resolve_path(filename)

Get the path for this filename. If the filename doesn’t exist, it returns the document_root + filename.