Created
July 16, 2015 06:50
-
-
Save lehmannro/2d2127b7c839282a673d to your computer and use it in GitHub Desktop.
Skipping section levels in Docutils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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