Skip to content

Commit bf7c0a4

Browse files
committed
Fix multi-paragraph doxygen comments in functions
Previously multi-paragraph functions that used doxygen comments would get the paragraphs merged into one. This behaviour has now been fixed to preserve the mult-paragraph nature.
1 parent a6c3d9c commit bf7c0a4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Added
1515
Compilation args can now be specified with the
1616
``c_autodoc_compilation_args`` configuration value.
1717

18+
Fixes
19+
-----
20+
21+
* Fix parsing of multi-paragraph function documentation that used doxygen style
22+
markup. Previously multi-paragraph function documentation which used doxygen
23+
style markup would get merged in to one paragraph. Now the multi-paragraph
24+
nature is preserved.
25+
1826
`v0.4.0`_ (2020-12-27)
1927
==========================
2028

src/sphinx_c_autodoc/loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ def get_soup_doc(self) -> Optional[str]:
413413
body = self.get_paragraph(root.find("abstract", recursive=False))
414414
body += self.get_paragraph(root.find("discussion", recursive=False))
415415

416+
# Single newlines are tread as the same paragraph in restructured text,
417+
# providing 2 results in separate paragraphs.
418+
body = body.replace("\n", "\n\n")
419+
416420
for param in root.find_all("parameter"):
417421
name = param.find("name").text
418422
param_doc = self.get_paragraph(param.discussion)

tests/directives/test_autocfunction.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,32 @@ def test_doc(self, function, expected_doc, sphinx_state):
117117
# For whatever reason the as text comes back with double spacing, so we
118118
# knock it down to single spacing to make the expected string smaller.
119119
assert body.astext().replace("\n\n", "\n") == dedent(expected_doc)
120+
121+
def test_multiple_paragraph_doxgyen_comment(self, sphinx_state):
122+
"""
123+
Tests that when processing a multi paragraph doxygen comment that the
124+
multiple paragraphs are preserved.
125+
"""
126+
directive = AutodocDirective(
127+
"autocfunction",
128+
["functions.c::doxy_documented_parameters_no_returns"],
129+
{"members": None},
130+
None,
131+
None,
132+
None,
133+
None,
134+
sphinx_state,
135+
None,
136+
)
137+
output = directive.run()
138+
139+
# First item is the index entry
140+
assert 2 == len(output)
141+
body = output[1]
142+
143+
# first item is the function signature
144+
paragraphs = body.children[1]
145+
146+
# 3 paragraphs from the description, and then one more child for the
147+
# parameter listing
148+
assert 4 == len(paragraphs)

0 commit comments

Comments
 (0)