Re: publish_parts and table of contents?

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

On 2017-07-19, Tony Narlock wrote:

> I’m getting there,

> I’ve overrides the Writer and added a new visitor attribute for “toc”.

> visitor_attributes = Writer.visitor_attributes + ('toc', )

> So “toc” should be collected during assemble_parts.

> From here, I want to inject the TOC the document into “toc”.

> 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.

A good representation of its output can be gained, if you create a
`minimal example` sample document, translate it to pseudoxml and examine
the result.

If the toc represents the logical structure you want to show in your output
document, fine. You can leave the transform as-is.
If not, explain the changes you think are necessary.

That means, in my situation, the transform itself is OK as is.

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.



> There is also a directive for parsers.rst.directives.parts.Contents. I’m
> curious how I would go about injecting that.

This should be the class triggered by the ``.. contents::`` directive. It
will ensure the transform is called at the right time and does the right
thing.

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



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.

Thanks,

P.S. Using the new docutils 0.14rc2 release. Thanks Günter.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
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.