diff --git a/sphinx_needs/functions/functions.py b/sphinx_needs/functions/functions.py index 10f8962c5..34c1cd3e7 100644 --- a/sphinx_needs/functions/functions.py +++ b/sphinx_needs/functions/functions.py @@ -22,6 +22,7 @@ from sphinx_needs.data import NeedsInfoType, NeedsMutable, NeedsView, SphinxNeedsData from sphinx_needs.debug import measure_time_func from sphinx_needs.logging import get_logger, log_warning +from sphinx_needs.nodes import Need from sphinx_needs.utils import NEEDS_FUNCTIONS, match_variants logger = get_logger(__name__) @@ -203,6 +204,10 @@ def find_and_replace_node_content( return node else: for child in node.children: + if isinstance(child, (nodes.literal_block, nodes.literal, Need)): + # Do not parse literal blocks or nested needs + new_children.append(child) + continue new_child = find_and_replace_node_content(child, env, need) new_children.append(new_child) node.children = new_children diff --git a/tests/doc_test/doc_df_user_functions/index.rst b/tests/doc_test/doc_df_user_functions/index.rst index e9b4087cd..53cb210c1 100644 --- a/tests/doc_test/doc_df_user_functions/index.rst +++ b/tests/doc_test/doc_df_user_functions/index.rst @@ -16,3 +16,8 @@ DYNAMIC FUNCTIONS [[invalid]] [[unknown()]] + + .. code-block:: toml + + # this should not be a func + [[something]] diff --git a/tests/doc_test/doc_dynamic_functions/index.rst b/tests/doc_test/doc_dynamic_functions/index.rst index d504dfdbd..71f3705ec 100644 --- a/tests/doc_test/doc_dynamic_functions/index.rst +++ b/tests/doc_test/doc_dynamic_functions/index.rst @@ -25,3 +25,8 @@ DYNAMIC FUNCTIONS :tags: [[copy('id')]] Test a `link `_ + + .. spec:: TEST_6 + :id: TEST_6 + + nested id [[copy('id')]] diff --git a/tests/test_dynamic_functions.py b/tests/test_dynamic_functions.py index fcc94c698..e4652c73b 100644 --- a/tests/test_dynamic_functions.py +++ b/tests/test_dynamic_functions.py @@ -9,12 +9,24 @@ @pytest.mark.parametrize( "test_app", - [{"buildername": "html", "srcdir": "doc_test/doc_dynamic_functions"}], + [ + { + "buildername": "html", + "srcdir": "doc_test/doc_dynamic_functions", + "no_plantuml": True, + } + ], indirect=True, ) def test_doc_dynamic_functions(test_app): app = test_app app.build() + + warnings = strip_colors( + app._warning.getvalue().replace(str(app.srcdir) + os.sep, "srcdir/") + ).splitlines() + assert warnings == [] + html = Path(app.outdir, "index.html").read_text() assert "This is id SP_TOO_001" in html @@ -48,6 +60,8 @@ def test_doc_dynamic_functions(test_app): assert 'link' in html + assert "nested id TEST_6" in html + @pytest.mark.parametrize( "test_app",