Merge branch '3.x' into 7865_extract_abbr

This commit is contained in:
Takeshi KOMIYA 2020-06-29 02:04:40 +09:00 committed by GitHub
commit c4f0d70d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 7 deletions

View File

@ -20,7 +20,8 @@ Bugs fixed
* #7839: autosummary: cannot handle umlauts in function names
* #7865: autosummary: Failed to extract summary line when abbreviations found
* #7866: autosummary: Failed to extract correct summary line when docstring
contains a hyperlink target
* #7715: LaTeX: ``numfig_secnum_depth > 1`` leads to wrong figure links
* #7846: html theme: XML-invalid files were generated

View File

@ -499,6 +499,13 @@ def mangle_signature(sig: str, max_chars: int = 30) -> str:
def extract_summary(doc: List[str], document: Any) -> str:
"""Extract summary from docstring."""
def parse(doc: List[str], settings: Any) -> nodes.document:
state_machine = RSTStateMachine(state_classes, 'Body')
node = new_document('', settings)
node.reporter = NullReporter()
state_machine.run(doc, node)
return node
# Skip a blank lines at the top
while doc and not doc[0].strip():
@ -516,11 +523,7 @@ def extract_summary(doc: List[str], document: Any) -> str:
return ''
# parse the docstring
state_machine = RSTStateMachine(state_classes, 'Body')
node = new_document('', document.settings)
node.reporter = NullReporter()
state_machine.run(doc, node)
node = parse(doc, document.settings)
if not isinstance(node[0], nodes.paragraph):
# document starts with non-paragraph: pick up the first line
summary = doc[0].strip()
@ -534,7 +537,7 @@ def extract_summary(doc: List[str], document: Any) -> str:
for i in range(len(sentences)):
summary = ". ".join(sentences[:i + 1]).rstrip(".") + "."
node[:] = []
state_machine.run([summary], node)
node = parse(doc, document.settings)
if summary.endswith(WELL_KNOWN_ABBREVIATIONS):
pass
elif not node.traverse(nodes.system_message):

View File

@ -108,6 +108,12 @@ def test_extract_summary(capsys):
'=========']
assert extract_summary(doc, document) == 'blah blah'
# hyperlink target
doc = ['Do `this <https://www.sphinx-doc.org/>`_ and that. '
'blah blah blah.']
assert (extract_summary(doc, document) ==
'Do `this <https://www.sphinx-doc.org/>`_ and that.')
_, err = capsys.readouterr()
assert err == ''