mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #5182 from tk0miya/5158_autosummary_wrong_summary
Fix #5158: autosummary: module summary has been broken when it starts with heading
This commit is contained in:
commit
66c760840f
1
CHANGES
1
CHANGES
@ -50,6 +50,7 @@ Bugs fixed
|
|||||||
* #5167: autodoc: Fix formatting type annotations for tuples with more than two
|
* #5167: autodoc: Fix formatting type annotations for tuples with more than two
|
||||||
arguments
|
arguments
|
||||||
* #3329: i18n: crashed by auto-symbol footnote references
|
* #3329: i18n: crashed by auto-symbol footnote references
|
||||||
|
* #5158: autosummary: module summary has been broken when it starts with heading
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -471,21 +471,32 @@ def extract_summary(doc, document):
|
|||||||
doc = doc[:i]
|
doc = doc[:i]
|
||||||
break
|
break
|
||||||
|
|
||||||
# Try to find the "first sentence", which may span multiple lines
|
if doc == []:
|
||||||
sentences = periods_re.split(" ".join(doc)) # type: ignore
|
return ''
|
||||||
if len(sentences) == 1:
|
|
||||||
summary = sentences[0].strip()
|
# parse the docstring
|
||||||
|
state_machine = RSTStateMachine(state_classes, 'Body')
|
||||||
|
node = new_document('', document.settings)
|
||||||
|
node.reporter = NullReporter()
|
||||||
|
state_machine.run(doc, node)
|
||||||
|
|
||||||
|
if not isinstance(node[0], nodes.paragraph):
|
||||||
|
# document starts with non-paragraph: pick up the first line
|
||||||
|
summary = doc[0].strip()
|
||||||
else:
|
else:
|
||||||
summary = ''
|
# Try to find the "first sentence", which may span multiple lines
|
||||||
state_machine = RSTStateMachine(state_classes, 'Body')
|
sentences = periods_re.split(" ".join(doc)) # type: ignore
|
||||||
while sentences:
|
if len(sentences) == 1:
|
||||||
summary += sentences.pop(0) + '.'
|
summary = sentences[0].strip()
|
||||||
node = new_document('', document.settings)
|
else:
|
||||||
node.reporter = NullReporter()
|
summary = ''
|
||||||
state_machine.run([summary], node)
|
while sentences:
|
||||||
if not node.traverse(nodes.system_message):
|
summary += sentences.pop(0) + '.'
|
||||||
# considered as that splitting by period does not break inline markups
|
node[:] = []
|
||||||
break
|
state_machine.run([summary], node)
|
||||||
|
if not node.traverse(nodes.system_message):
|
||||||
|
# considered as that splitting by period does not break inline markups
|
||||||
|
break
|
||||||
|
|
||||||
# strip literal notation mark ``::`` from tail of summary
|
# strip literal notation mark ``::`` from tail of summary
|
||||||
summary = literal_re.sub('.', summary)
|
summary = literal_re.sub('.', summary)
|
||||||
|
@ -85,6 +85,11 @@ def test_extract_summary(capsys):
|
|||||||
doc = ['blah blah::']
|
doc = ['blah blah::']
|
||||||
assert extract_summary(doc, document) == 'blah blah.'
|
assert extract_summary(doc, document) == 'blah blah.'
|
||||||
|
|
||||||
|
# heading
|
||||||
|
doc = ['blah blah',
|
||||||
|
'=========']
|
||||||
|
assert extract_summary(doc, document) == 'blah blah'
|
||||||
|
|
||||||
_, err = capsys.readouterr()
|
_, err = capsys.readouterr()
|
||||||
assert err == ''
|
assert err == ''
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user