mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6261 from tk0miya/refactor_glossary3
Fix commented term in glossary directive is wrongly recognized
This commit is contained in:
commit
089a94080f
1
CHANGES
1
CHANGES
@ -75,6 +75,7 @@ Bugs fixed
|
||||
* #6230: Inappropriate node_id has been generated by glossary directive if term
|
||||
is consisted by non-ASCII characters
|
||||
* #6213: ifconfig: contents after headings are not shown
|
||||
* commented term in glossary directive is wrongly recognized
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -305,6 +305,7 @@ class Glossary(SphinxDirective):
|
||||
# first, collect single entries
|
||||
entries = [] # type: List[Tuple[List[Tuple[str, str, int]], StringList]]
|
||||
in_definition = True
|
||||
in_comment = False
|
||||
was_empty = True
|
||||
messages = [] # type: List[nodes.Node]
|
||||
for line, (source, lineno) in zip(self.content, self.content.items):
|
||||
@ -318,7 +319,11 @@ class Glossary(SphinxDirective):
|
||||
if line and not line[0].isspace():
|
||||
# enable comments
|
||||
if line.startswith('.. '):
|
||||
in_comment = True
|
||||
continue
|
||||
else:
|
||||
in_comment = False
|
||||
|
||||
# first term of definition
|
||||
if in_definition:
|
||||
if not was_empty:
|
||||
@ -339,6 +344,8 @@ class Glossary(SphinxDirective):
|
||||
messages.append(self.state.reporter.warning(
|
||||
_('glossary seems to be misformatted, check indentation'),
|
||||
source=source, line=lineno))
|
||||
elif in_comment:
|
||||
pass
|
||||
else:
|
||||
if not in_definition:
|
||||
# first line of definition, determines indentation
|
||||
|
@ -177,7 +177,7 @@ def test_glossary_comment(app):
|
||||
" description\n"
|
||||
" .. term2\n"
|
||||
" description\n"
|
||||
" .. description\n")
|
||||
" description\n")
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (
|
||||
[glossary, definition_list, definition_list_item, ([term, ("term1",
|
||||
@ -185,9 +185,33 @@ def test_glossary_comment(app):
|
||||
definition)],
|
||||
))
|
||||
assert_node(doctree[0][0][0][1],
|
||||
[nodes.definition, nodes.paragraph, "description"])
|
||||
|
||||
|
||||
def test_glossary_comment2(app):
|
||||
text = (".. glossary::\n"
|
||||
"\n"
|
||||
" term1\n"
|
||||
" description\n"
|
||||
"\n"
|
||||
" .. term2\n"
|
||||
" term3\n"
|
||||
" description\n"
|
||||
" description\n")
|
||||
doctree = restructuredtext.parse(app, text)
|
||||
assert_node(doctree, (
|
||||
[glossary, definition_list, ([definition_list_item, ([term, ("term1",
|
||||
index)],
|
||||
definition)],
|
||||
[definition_list_item, ([term, ("term3",
|
||||
index)],
|
||||
definition)])],
|
||||
))
|
||||
assert_node(doctree[0][0][0][1],
|
||||
[nodes.definition, nodes.paragraph, "description"])
|
||||
assert_node(doctree[0][0][1][1],
|
||||
[nodes.definition, nodes.paragraph, ("description\n"
|
||||
"description\n"
|
||||
".. description")])
|
||||
"description")])
|
||||
|
||||
|
||||
def test_glossary_sorted(app):
|
||||
|
Loading…
Reference in New Issue
Block a user