Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sphinx_needs/needs.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def setup(app: Sphinx) -> dict[str, Any]:
html=(visitor_dummy, visitor_dummy),
latex=(visitor_dummy, visitor_dummy),
)
app.add_node(
NeedRef,
html=(visitor_dummy, visitor_dummy),
latex=(visitor_dummy, visitor_dummy),
)

########################################################################
# DIRECTIVES
Expand Down
11 changes: 11 additions & 0 deletions tests/doc_test/doc_role_need_in_heading/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extensions = ["sphinx_needs"]

needs_types = [
{
"directive": "req",
"title": "Requirement",
"prefix": "RE_",
"color": "#BFD8D2",
"style": "node",
},
]
10 changes: 10 additions & 0 deletions tests/doc_test/doc_role_need_in_heading/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Test Need Role in Heading
=========================

.. req:: My Requirement
:id: REQ_001

Section with need ref :need:`REQ_001`
-------------------------------------

Some content here.
24 changes: 24 additions & 0 deletions tests/test_role_need_in_heading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re
from pathlib import Path

import pytest


@pytest.mark.parametrize(
"test_app",
[{"buildername": "html", "srcdir": "doc_test/doc_role_need_in_heading"}],
indirect=True,
)
def test_role_need_in_heading(test_app):
app = test_app
app.build()
html = Path(app.outdir, "index.html").read_text()

# The heading should contain a reference to the need
heading = re.search(r"<h2>(.*?)</h2>", html, re.DOTALL)
assert heading is not None, "Expected an h2 heading in the output"
heading_content = heading.group(1)

# The heading should contain a link to the need with the resolved title
assert "REQ_001" in heading_content
assert "My Requirement" in heading_content
Loading