diff --git a/CHANGES b/CHANGES index 82d5f29e5..cc2dbf681 100644 --- a/CHANGES +++ b/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 -------- diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 4e1bffa21..c5b3e4e43 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -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 diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index d4c8869ca..dd77c11dd 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -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):