我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用docutils.nodes.NodeFound()。
def visit_list_item(self, node): children = [] for child in node.children: if not isinstance(child, nodes.Invisible): children.append(child) if (children and isinstance(children[0], nodes.paragraph) and (isinstance(children[-1], nodes.bullet_list) or isinstance(children[-1], nodes.enumerated_list))): children.pop() if len(children) <= 1: return else: raise nodes.NodeFound # def visit_bullet_list(self, node): # pass # def visit_enumerated_list(self, node): # pass # def visit_paragraph(self, node): # raise nodes.SkipNode
def check_simple_list(self, node): """Check for a simple list that can be rendered compactly.""" visitor = SimpleListChecker(self.document) try: node.walk(visitor) except nodes.NodeFound: return False else: return True # Compact lists # ------------ # Include definition lists and field lists (in addition to ordered # and unordered lists) in the test if a list is "simple" (cf. the # html4css1.HTMLTranslator docstring and the SimpleListChecker class at # the end of this file).
def check_simple_list(self, node): """Check for a simple list that can be rendered compactly.""" visitor = SimpleListChecker(self.document) try: node.walk(visitor) except nodes.NodeFound: return None else: return 1
def process_refonly_bullet_lists(self, docname, doctree): """Change refonly bullet lists to use compact_paragraphs. Specifically implemented for 'Indices and Tables' section, which looks odd when html_compact_lists is false. """ if self.config.html_compact_lists: return class RefOnlyListChecker(nodes.GenericNodeVisitor): """Raise `nodes.NodeFound` if non-simple list item is encountered. Here 'simple' means a list item containing only a paragraph with a single reference in it. """ def default_visit(self, node): raise nodes.NodeFound def visit_bullet_list(self, node): pass def visit_list_item(self, node): children = [] for child in node.children: if not isinstance(child, nodes.Invisible): children.append(child) if len(children) != 1: raise nodes.NodeFound if not isinstance(children[0], nodes.paragraph): raise nodes.NodeFound para = children[0] if len(para) != 1: raise nodes.NodeFound if not isinstance(para[0], addnodes.pending_xref): raise nodes.NodeFound raise nodes.SkipChildren def invisible_visit(self, node): """Invisible nodes should be ignored.""" pass def check_refonly_list(node): """Check for list with only references in it.""" visitor = RefOnlyListChecker(doctree) try: node.walk(visitor) except nodes.NodeFound: return False else: return True for node in doctree.traverse(nodes.bullet_list): if check_refonly_list(node): for item in node.traverse(nodes.list_item): para = item[0] ref = para[0] compact_para = addnodes.compact_paragraph() compact_para += ref item.replace(para, compact_para)