我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用docutils.nodes.doctest_block()。
def apply(self): # move doctest blocks out of blockquotes for node in self.document.traverse(nodes.block_quote): if all(isinstance(child, nodes.doctest_block) for child in node.children): node.replace_self(node.children) # combine successive doctest blocks # for node in self.document.traverse(nodes.doctest_block): # if node not in node.parent.children: # continue # parindex = node.parent.index(node) # while len(node.parent) > parindex+1 and \ # isinstance(node.parent[parindex+1], nodes.doctest_block): # node[0] = nodes.Text(node[0] + '\n\n' + # node.parent[parindex+1][0]) # del node.parent[parindex+1]
def doctest(self, match, context, next_state): data = '\n'.join(self.state_machine.get_text_block()) # TODO: prepend class value ['pycon'] (Python Console) # parse with `directives.body.CodeBlock` (returns literal-block # with class "code" and syntax highlight markup). self.parent += nodes.doctest_block(data, data) return [], next_state, []
def doctest(self, match, context, next_state): data = '\n'.join(self.state_machine.get_text_block()) self.parent += nodes.doctest_block(data, data) return [], next_state, []