Change initial header level in docutils

I use reStructuredText on parts of this site to write HTML content. But as the main headers don't originate from the rst content I need to start with an h2 tag. It's just a matter of rtfm but here's a solution.

from docutils.core import publish_parts
print publish_parts(rst_content, writer_name='html',settings_overrides={
                    'initial_header_level': 2,})['html_body']

Published on Feb. 19, 2013 at 8:36 p.m. by Nicolas and tagged reStructuredText. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.