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']

2 comments

  1. avatar
    wrote this comment on
    Thanks for posting this. Isn't it interesting how what might at first seem like a pointless post can save someone hours of hell?
    1. avatar
      wrote this comment on
      Yeah, it took me a while to figure it out, and the documentation.. well, let's just say I've seen better docs.

Start a new thread

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