mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #7866: autosummary: Failed to extract correct summary line
A hyperlink target in the docstring causes a system_error because node_ids are cached expectedly during extracting a summary.
This commit is contained in:
parent
03e85df617
commit
4fa596ba4c
2
CHANGES
2
CHANGES
@ -19,6 +19,8 @@ Bugs fixed
|
|||||||
----------
|
----------
|
||||||
|
|
||||||
* #7839: autosummary: cannot handle umlauts in function names
|
* #7839: autosummary: cannot handle umlauts in function names
|
||||||
|
* #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
|
* #7715: LaTeX: ``numfig_secnum_depth > 1`` leads to wrong figure links
|
||||||
* #7846: html theme: XML-invalid files were generated
|
* #7846: html theme: XML-invalid files were generated
|
||||||
|
|
||||||
|
@ -497,6 +497,13 @@ def mangle_signature(sig: str, max_chars: int = 30) -> str:
|
|||||||
|
|
||||||
def extract_summary(doc: List[str], document: Any) -> str:
|
def extract_summary(doc: List[str], document: Any) -> str:
|
||||||
"""Extract summary from docstring."""
|
"""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
|
# Skip a blank lines at the top
|
||||||
while doc and not doc[0].strip():
|
while doc and not doc[0].strip():
|
||||||
@ -514,11 +521,7 @@ def extract_summary(doc: List[str], document: Any) -> str:
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
# parse the docstring
|
# parse the docstring
|
||||||
state_machine = RSTStateMachine(state_classes, 'Body')
|
node = parse(doc, document.settings)
|
||||||
node = new_document('', document.settings)
|
|
||||||
node.reporter = NullReporter()
|
|
||||||
state_machine.run(doc, node)
|
|
||||||
|
|
||||||
if not isinstance(node[0], nodes.paragraph):
|
if not isinstance(node[0], nodes.paragraph):
|
||||||
# document starts with non-paragraph: pick up the first line
|
# document starts with non-paragraph: pick up the first line
|
||||||
summary = doc[0].strip()
|
summary = doc[0].strip()
|
||||||
@ -532,7 +535,7 @@ def extract_summary(doc: List[str], document: Any) -> str:
|
|||||||
while sentences:
|
while sentences:
|
||||||
summary += sentences.pop(0) + '.'
|
summary += sentences.pop(0) + '.'
|
||||||
node[:] = []
|
node[:] = []
|
||||||
state_machine.run([summary], node)
|
node = parse(doc, document.settings)
|
||||||
if not node.traverse(nodes.system_message):
|
if not node.traverse(nodes.system_message):
|
||||||
# considered as that splitting by period does not break inline markups
|
# considered as that splitting by period does not break inline markups
|
||||||
break
|
break
|
||||||
|
@ -108,6 +108,12 @@ def test_extract_summary(capsys):
|
|||||||
'=========']
|
'=========']
|
||||||
assert extract_summary(doc, document) == 'blah blah'
|
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()
|
_, err = capsys.readouterr()
|
||||||
assert err == ''
|
assert err == ''
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user