Skip to content

Instantly share code, notes, and snippets.

@lehmannro
Created July 16, 2015 06:50
Show Gist options
  • Save lehmannro/2d2127b7c839282a673d to your computer and use it in GitHub Desktop.
Save lehmannro/2d2127b7c839282a673d to your computer and use it in GitHub Desktop.
Skipping section levels in Docutils
from docutils import utils, nodes, core
document = utils.new_document('<source>')
document.append(
nodes.section('', # bogus section
nodes.section('', # level 2 section
nodes.title('', 'second level'), # <h2>
),
),
)
print document
# => <document source="<source>"><section><section><title>my h2</title>
# </section></section></document>
output = core.publish_from_doctree(document, writer_name='html4css1')
print output[output.find('<body>'):]
# => <body>
# <div class="document">
# <div class="section">
# <div class="section">
# <h2>my h2</h2>
# </div>
# </div>
# </div>
# </body>
# </html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment