Skip to content

Instantly share code, notes, and snippets.

@kennethzfeng
Created August 31, 2014 22:16
Show Gist options
  • Select an option

  • Save kennethzfeng/aed4007ef1fea1700b7f to your computer and use it in GitHub Desktop.

Select an option

Save kennethzfeng/aed4007ef1fea1700b7f to your computer and use it in GitHub Desktop.
rsStructureText to Node Tree using docutils
"""
Parse reStructureText into Node Tree
"""
from docutils.parsers.rst import Parser
from docutils.utils import new_document
from docutils.frontend import OptionParser
import logging
PATH = 'sample.rst'
parser = Parser()
with open(PATH, 'rb') as f:
data = f.read()
logging.debug('Loaded %d lines' % len(data))
settings = OptionParser(components=(Parser,)).get_default_values()
document = new_document(PATH, settings)
parser.parse(data, document)
# Play with the document

Title

Subtitle

Titles are underlined (or over- and underlined) with a printing nonalphanumeric 7-bit ASCII character. Recommended choices are "= - ` : ' " ~ ^ _ * + # < >". The underline/overline must be at least as long as the title text.

A lone top-level (sub)section is lifted up to be the document's (sub)title.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment