def _parse_definition_list(
def_list_node: nodes.definition_list) -> ExtraContentDict:
"""Parse a definition list inside the directive.
Args:
def_list_node: A definition list node containing definitions for
extending the Sphinx output.
Raises:
ValueError: The given classifier was unrecognized.
Returns:
A dict where keys are item IDs and values contain the classifiers
and the content as lists of docutils nodes.
"""
definitions = collections.defaultdict(lambda: None)
for node in def_list_node:
if not isinstance(node, nodes.definition_list_item):
continue
term = _get_matching_child(node, nodes.term, last=False).astext()
classifiers = set()
for child_node in node.children:
if not isinstance(child_node, nodes.classifier):
continue
classifier = child_node.astext()
if classifier not in ALL_CLASSIFIERS:
raise ValueError("unknown classifier '{0}'".format(classifier))
classifiers.add(classifier)
if not classifiers & CONTENT_CLASSIFIERS:
classifiers.add("@after")
if not classifiers & MARKUP_CLASSIFIERS:
classifiers.add("@auto")
content = _get_matching_child(
node, nodes.definition, last=False).children
if not definitions[term]:
definitions[term] = []
definitions[term].append(ExtraContent(classifiers, content))
return definitions
评论列表
文章目录