Skip to content

Conversation

@tim-nordell-nimbelink
Copy link
Contributor

The find_and_replace_node_content function breaks parent-child node relationships since it does not go through the docutils tools for assigning node children. Utilize one of the built-in docutils methods [1] for this since it correctly assigns the parent-child relationship of each node.

Notably, the sphinxcontrib-spelling [2] extension is broken by this broken parent-child relationship since if something is misspelled it tries to identify which source line was impacted. When a node is added as a child, setup_child(...) [3] code fixes up the source/line location with the parent's information if needed.

A test has been added at the top-level which covers every single test run by adding a build hook into the "doctree-resolved" hook. This test is fairly simple - check each node (outside of the top node) and validate that it has a parent assigned.

[1] https://github.com/docutils/docutils/blob/4e912fe000b1b6dc1466c0ad1c3d1787d40fd96d/docutils/docutils/nodes.py#L788-L794
[2] https://pypi.org/project/sphinxcontrib-spelling/
[3] https://github.com/docutils/docutils/blob/4e912fe000b1b6dc1466c0ad1c3d1787d40fd96d/docutils/docutils/nodes.py#L150-L157

The find_and_replace_node_content function breaks parent-child node
relationships since it does not go through the docutils tools for
assigning node children. The Element class in docutils will [1] iterate
over each added child; we'll mimic that here.  (We can't use the Element
variant since we're only guaranteed to be of type Node, which doesn't have
these helper functions, unfortunately.)

Notably, the sphinxcontrib-spelling [2] extension is broken by this
broken parent-child relationship since if something is misspelled it
tries to identify which source line was impacted. When a node is added
as a child, setup_child(...) [3] code fixes up the source/line location
with the parent's information if needed.

A test has been added at the top-level which covers every single test
run by adding a build hook into the "doctree-resolved" hook. This test
is fairly simple - check each node (outside of the top node) and
validate that it has a parent assigned.

[1] https://github.com/docutils/docutils/blob/4e912fe000b1b6dc1466c0ad1c3d1787d40fd96d/docutils/docutils/nodes.py#L788-L794
[2] https://pypi.org/project/sphinxcontrib-spelling/
[3] https://github.com/docutils/docutils/blob/4e912fe000b1b6dc1466c0ad1c3d1787d40fd96d/docutils/docutils/nodes.py#L150-L157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant