Merge pull request #6261 from tk0miya/refactor_glossary3

Fix commented term in glossary directive is wrongly recognized
This commit is contained in:
Takeshi KOMIYA 2019-04-07 18:46:15 +09:00 committed by GitHub
commit 089a94080f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 3 deletions

View File

@ -75,6 +75,7 @@ Bugs fixed
* #6230: Inappropriate node_id has been generated by glossary directive if term * #6230: Inappropriate node_id has been generated by glossary directive if term
is consisted by non-ASCII characters is consisted by non-ASCII characters
* #6213: ifconfig: contents after headings are not shown * #6213: ifconfig: contents after headings are not shown
* commented term in glossary directive is wrongly recognized
Testing Testing
-------- --------

View File

@ -305,6 +305,7 @@ class Glossary(SphinxDirective):
# first, collect single entries # first, collect single entries
entries = [] # type: List[Tuple[List[Tuple[str, str, int]], StringList]] entries = [] # type: List[Tuple[List[Tuple[str, str, int]], StringList]]
in_definition = True in_definition = True
in_comment = False
was_empty = True was_empty = True
messages = [] # type: List[nodes.Node] messages = [] # type: List[nodes.Node]
for line, (source, lineno) in zip(self.content, self.content.items): 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(): if line and not line[0].isspace():
# enable comments # enable comments
if line.startswith('.. '): if line.startswith('.. '):
in_comment = True
continue continue
else:
in_comment = False
# first term of definition # first term of definition
if in_definition: if in_definition:
if not was_empty: if not was_empty:
@ -339,6 +344,8 @@ class Glossary(SphinxDirective):
messages.append(self.state.reporter.warning( messages.append(self.state.reporter.warning(
_('glossary seems to be misformatted, check indentation'), _('glossary seems to be misformatted, check indentation'),
source=source, line=lineno)) source=source, line=lineno))
elif in_comment:
pass
else: else:
if not in_definition: if not in_definition:
# first line of definition, determines indentation # first line of definition, determines indentation

View File

@ -177,7 +177,7 @@ def test_glossary_comment(app):
" description\n" " description\n"
" .. term2\n" " .. term2\n"
" description\n" " description\n"
" .. description\n") " description\n")
doctree = restructuredtext.parse(app, text) doctree = restructuredtext.parse(app, text)
assert_node(doctree, ( assert_node(doctree, (
[glossary, definition_list, definition_list_item, ([term, ("term1", [glossary, definition_list, definition_list_item, ([term, ("term1",
@ -185,9 +185,33 @@ def test_glossary_comment(app):
definition)], definition)],
)) ))
assert_node(doctree[0][0][0][1], 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" [nodes.definition, nodes.paragraph, ("description\n"
"description\n" "description")])
".. description")])
def test_glossary_sorted(app): def test_glossary_sorted(app):