Skip to content

Commit

Permalink
🐛 FIX dynamic functions in need content
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Sep 2, 2024
1 parent 1cf4632 commit b83de30
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sphinx_needs/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/doc_test/doc_df_user_functions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ DYNAMIC FUNCTIONS
[[invalid]]

[[unknown()]]

.. code-block:: toml
# this should not be a func
[[something]]
5 changes: 5 additions & 0 deletions tests/doc_test/doc_dynamic_functions/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ DYNAMIC FUNCTIONS
:tags: [[copy('id')]]

Test a `link <http://www.[[copy('id')]]>`_

.. spec:: TEST_6
:id: TEST_6

nested id [[copy('id')]]
16 changes: 15 additions & 1 deletion tests/test_dynamic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -48,6 +60,8 @@ def test_doc_dynamic_functions(test_app):

assert '<a class="reference external" href="http://www.TEST_5">link</a>' in html

assert "nested id TEST_6" in html


@pytest.mark.parametrize(
"test_app",
Expand Down

0 comments on commit b83de30

Please sign in to comment.