I can confirm getting the node information.
The issue I have is getting the HTML from toc_list.
The only other problem I have is:
from docutils.writers.html5_polyglot import Writer
core.publish_from_doctree(toc_list, writer=Writer())
Traceback (most recent call last):
File â./try2.py", line 48, in <module>
core.publish_from_doctree(toc_list, writer=Writer())
File ".venv/lib/python3.6/site-packages/docutils/core.py", line 521, in
publish_from_doctree
return pub.publish(enable_exit_status=enable_exit_status)
File ".venv/lib/python3.6/site-packages/docutils/core.py", line 218, in
publish
self.apply_transforms()
File ".venv/lib/python3.6/site-packages/docutils/core.py", line 199, in
apply_transforms
self.document.transformer.apply_transforms()
File â.venv/lib/python3.6/site-packages/docutils/transforms/__init__.py",
line 162, in apply_transforms
self.document.note_transform_message)
AttributeError: 'bullet_list' object has no attribute
'note_transform_message'
Post by Tony NarlockThanks for your help on this.
This is way trickier than it looks, with all due respect.
Just because you're trying to hack Docutils without a sufficiently
deep understanding of the internals.
Post by Tony NarlockClocked in almost
two days on this so far.
Hopefully this exercise has improved your understanding!
Post by Tony NarlockJust trying to get the table of contents separate from html_body.
Seriously
Post by Tony Narlockconsidering adding ..contents:: to the source, building HTML and ripping out
the ToC via LXML.
Love reStructuredText and docutils (been having quite a few internal
successes lately), but this particular task feels like going against the
grain.
Have you read the documentation? There's no one place for what you
want, it's spread out. See:
* http://docutils.sourceforge.net/docs/ref/transforms.html
* http://docutils.sourceforge.net/docs/peps/pep-0258.html#transformer
* http://docutils.sourceforge.net/docs/dev/hacking.html
Also, see the code. There's lots of inline documentation in docstrings
and comments.
Ultimately, you need to understand the flow of data in Docutils, how
all the components interrelate.
No, no, no, don't tug on that. You never know what it might be attached to.
â Buckaroo Banzai (during brain surgery)
I think the attached code will get you most of the way to where you want to
go.
DG
Post by Tony NarlockOn July 21, 2017 at 3:39:58 PM, Guenter Milde via Docutils-users
Post by Tony Narlockhttps://gist.github.com/tony/1a03b7668c9e33672f4465dd63c6076b
No time to look.
Post by Tony NarlockOn July 20, 2017 at 11:54:07 AM, Guenter Milde via Docutils-users (
Post by Tony NarlockOn July 19, 2017 at 5:27:15 PM, Guenter Milde via Docutils-users (
...
I suppose rather than messing with "parts", you can use the publish_*
Don't use ``.. contents..`` in the source.
1. Parse the rst source with publish_doctree()
Returns a doctree object.
2. Export doctree to HTML with publish_from_doctree()
Does this work?
Yes, this just gives CSS + HTML for way more than I need. Am I supposed to
see anything special in the HTML or are you just checking that
publish_doctree+publish_from_doctree works (it does).
Way more than html_body (all I need, aside from ToC). And Iâm not sure what
I can do with this content?
Post by Tony NarlockPost by Tony Narlock3. Run the toc-generating transform on the doctree.
Returns a "toc doctree".
Where would it be?
In docutils/transforms/parts.py
Post by Tony NarlockAm I applying the transform correctly in the paste?
Post by Tony Narlock4. Export the "toc doctree" with publish_from_doctree().
Assuming Iâm running the transform correctly, I see no difference in the
output.
So I suppose you don't apply it correctly.
The idea is to collect generate a TOC by travelling over the doctree in
the same manner as it is done by the "Contents" transform.
Therefore, it should be possible to use
docutils.transforms.parts.Contents.build_contents() and pass it the
startnode of the doctree returned by "publish_parts".
Post by Tony NarlockPost by Tony NarlockThis is just an idea, not tested and detailled.
GÃŒnter