-
-
Save tony/c4fc5661fcd4b7de71c65dd8a52c9ea4 to your computer and use it in GitHub Desktop.
What I want parts["toc"] in from HTMLWriter + publish_parts to return
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from docutils.core import publish_parts | |
from docutils.writers.html5_polyglot import Writer | |
toc = """ | |
.. contents:: | |
""" | |
contents = """ | |
========= | |
Hey world | |
========= | |
what's up | |
--------- | |
ok | |
""" | |
# parts for both, in order show a diff of what I want/do not want | |
both = publish_parts( | |
source=toc+contents, | |
writer=Writer(), | |
) | |
# parts for the contents | |
just_the_contents = publish_parts( | |
source=contents, | |
writer=Writer(), | |
) | |
print('All I want to have in html_body is: \n%s' % | |
just_the_contents["html_body"]) | |
desired_output = """ | |
<div class="contents topic" id="contents"> | |
<p class="topic-title first">Contents</p> | |
<ul class="simple"> | |
<li><p><a class="reference internal" href="#hey-world" id="id1">Hey world</a></p> | |
<ul> | |
<li><p><a class="reference internal" href="#what-s-up" id="id2">what's up</a></p></li> | |
</ul> | |
</li> | |
</ul> | |
</div> | |
""" | |
print( | |
'\n\nWhat I want just_the_contents["toc"] to show: \n%s' % desired_output | |
) | |
""" | |
1. Currently, table of contents is only outputted through directive. | |
2. I do not to position table of contents in the RST. (therefore, I | |
specifically do not want it in html_body) | |
3. I want it to be available in "toc" *without* using the directive in the | |
source. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment