Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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