From: Tony N. <to...@gi...> - 2017-07-20 13:10:35
|
This has been helpful, thank you. It would be indispensable to get a code example or demonstration. On July 19, 2017 at 5:27:15 PM, Guenter Milde via Docutils-users ( doc...@li...) wrote: On 2017-07-19, Tony Narlock wrote: > On July 19, 2017 at 11:33:54 AM, Guenter Milde via Docutils-users ( > doc...@li...) 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. I am looking at those, I think I have it figured out how to add “toc”. This is done by appending ’toc' to visitor_attributes. This gets collected during assemble_parts(). But I’m not sure of where and how to inject a directive (e.g. Contents) via Writer. That’d be needed to get the table of contents to be added to “toc”. 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 Doc...@li... https://lists.sourceforge.net/lists/listinfo/docutils-users Please use "Reply All" to reply to the list. |