sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Cannot update document object from my own SphinxPostTransform

Open dachym opened this issue 3 years ago • 1 comments

Describe the bug

I try to add nodes in top of a document during my SphinxPostTransform (ClassListTransform) with the insert method. I'm doing the same method in ClassDirectiveDoc and it's works perfectly. In the ClassListTransform, I have the document reference registered in ClassDirectiveDoc which allows me to call the same insert method.

I'm sorry, I didn't succeed to add the nodes with ClassDirectiveDoc contrary to the equivalent class in my project, but I'm using the same code. It's supposed to add Warning in my example rst doctree. And the node that I add in my ClassListTransform is supposed to add another warning node in the same example doctree document.

In debug, I have seen that I have my example document object updated correctly, but when I have checked in my generated html file class_list.html, the warning from ClassDirectiveDoc was added but the one from ClassListTransform. Is there any method that I have to call to the notify the HTML Builder that my docstree has been updated ?

How to Reproduce

$ git clone https://github.com/dachym/sphinx_create_reference
$ cd sphinx_create_reference
$ make html
$ # open build/html/class_list.html

Expected behavior

The build/html/_modules/modules/first_module/example.html should contains two warning node, one from ClassDirectiveDoc and one from ClassListTransform. In my original code, I have my warning node from "ActualDirectiveDoc" but in this example for another reason that I don't understand. Anyway, I don't have the warning from ClassListTransform.

Your project

https://github.com/dachym/sphinx_create_reference

Screenshots

No response

OS

Linux

Python version

Python 3.10

Sphinx version

4.5.0

Sphinx extensions

No response

Extra tools

autodoc, napoleon, sphinx_autodoc_typehints, doctest, intersphinx, todo, coverage, imgmath, ifconfig, viewcode, githubpages, graphviz, sphinx_rtd_theme

Additional context

No response

dachym avatar Jul 11 '22 09:07 dachym

Unfortunately, you can't modify other documents via the PostTransform. It can modify only the current processing document (self.document). If you'd like to modify the document calling class_directive_doc directive, you also need to handle it on another PostTransform.

tk0miya avatar Jul 16 '22 05:07 tk0miya