Re: publish_parts and table of contents?

Guenter Milde via Docutils-users <[email protected]>
Newsgroups gmane.text.docutils.user
Message-ID <[email protected]>
On 2017-07-19, Tony Narlock wrote:
> On July 19, 2017 at 11:33:54 AM, Guenter Milde via Docutils-users (
> [email protected]) wrote:

...

>> There’s transforms.parts.Content(), but I’m not sure where and how I’d put
>> it into play.

> The transform generates the TOC by travelling the document tree after
> parsing is complete.

> I just want publish_parts to output the HTML contents of TOC to its own
> part.

> e.g., In the same way publish_parts gives “html_body” and “fragment”, I
> want it to return “toc”, which is the HTML output of the table of contents.

Then, you can leave the transform and directive alone.

> Yes. I pretty much want a new “part” created by HTMLWriter when
> publish_parts is used that only contains “.. contents::” output.



>> So how do you think I can go about that? Could you give me a code example
>> to how I could get the equivalent of .. contents:: showing up in a “toc”
>> part of writer?

> Rather, you should provide a minimal working example showing what you want
> to achieve (+ a diff between current and desired output).

> https://gist.github.com/tony/c4fc5661fcd4b7de71c65dd8a52c9ea4

Which contains the description:

> 1. Currently, table of contents is only outputted through directive.
...
> 3. I want it to be available in "toc" *without* using the directive in the
>    source.

For this, you would need to run the "Contents" transform also if the
document does not contain the "contents" directive . Dont know how to do
this and whether it is worth the effort. I suppose, a wrapper adding the
directive to the input string may achieve the same result far more easy.


> 2. I do not to position table of contents in the RST. (therefore, I
>    specifically do not want it in html_body)

You can suppress it with the "strip-elements-with-class" setting.


For an example of parts implementation, have a look how the "footer" part
is implemented in writers/_html_base.py. It is not trivial, make sure to
understand the code around every occurence of "footer" in the source file.

Günter


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Docutils-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-users

Please use "Reply All" to reply to the list.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.