diff --git a/sphinx_needs/functions/functions.py b/sphinx_needs/functions/functions.py index 873f6e23a..197b94250 100644 --- a/sphinx_needs/functions/functions.py +++ b/sphinx_needs/functions/functions.py @@ -257,6 +257,8 @@ def find_and_replace_node_content( new_child = find_and_replace_node_content(child, env, need) new_children.append(new_child) node.children = new_children + for subchild in node.children: + node.setup_child(subchild) else: node = nodes.Text(new_text) return node @@ -269,6 +271,8 @@ def find_and_replace_node_content( new_child = find_and_replace_node_content(child, env, need) new_children.append(new_child) node.children = new_children + for subchild in node.children: + node.setup_child(subchild) return node diff --git a/tests/conftest.py b/tests/conftest.py index 72b8631ad..5537e58e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -254,6 +254,13 @@ def sphinx_test_tempdir(request) -> path: return sphinx_test_tempdir +def test_check_parent_child(app: Sphinx, doctree: document, docname: str): + for idx, node in enumerate(doctree.findall()): + if idx == 0: + continue + assert node.parent + + @pytest.fixture(scope="function") def test_app(make_app, sphinx_test_tempdir, request): """ @@ -330,6 +337,8 @@ def test_app(make_app, sphinx_test_tempdir, request): # ``test_js`` behaves like a method. app.test_js = test_js.__get__(app, Sphinx) + app.connect("doctree-resolved", test_check_parent_child, priority=999) + yield app app.cleanup()