Skip to content

Commit a4a0b97

Browse files
authored
Merge pull request #9569 from jakelishman/fix-autosummary-sections
Fix #9568: autosummary: summarise overlined sectioned headings correctly
2 parents baacc26 + 760820f commit a4a0b97

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Bugs fixed
3131
* #9522: autodoc: PEP 585 style typehints having arguments (ex. ``list[int]``)
3232
are not displayed well
3333
* #9481: autosummary: some warnings contain non-existing filenames
34+
* #9568: autosummary: summarise overlined sectioned headings correctly
3435
* #9481: c domain: some warnings contain non-existing filenames
3536
* #9481: cpp domain: some warnings contain non-existing filenames
3637
* #9456: html search: abbreation marks are inserted to the search result if

sphinx/ext/autosummary/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ def parse(doc: List[str], settings: Any) -> nodes.document:
540540

541541
# parse the docstring
542542
node = parse(doc, document.settings)
543-
if not isinstance(node[0], nodes.paragraph):
543+
if isinstance(node[0], nodes.section):
544+
# document starts with a section heading, so use that.
545+
summary = node[0].astext().strip()
546+
elif not isinstance(node[0], nodes.paragraph):
544547
# document starts with non-paragraph: pick up the first line
545548
summary = doc[0].strip()
546549
else:

tests/test_ext_autosummary.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ def test_extract_summary(capsys):
109109
'=========']
110110
assert extract_summary(doc, document) == 'blah blah'
111111

112+
doc = ['=========',
113+
'blah blah',
114+
'=========']
115+
assert extract_summary(doc, document) == 'blah blah'
116+
112117
# hyperlink target
113118
doc = ['Do `this <https://www.sphinx-doc.org/>`_ and that. '
114119
'blah blah blah.']

0 commit comments

Comments
 (0)