Change initial header level in docutils

Font

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.

Raw
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?
  2. 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.

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo