我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用docutils.nodes.rubric()。
def process_readingtime_nodes(app, doctree, fromdocname): env = app.builder.env count = 0 for node in doctree.traverse(nodes.paragraph): tt=node.astext() count+=len(tt.split(" ")) for node in doctree.traverse(ReadingTime): para = nodes.rubric() minutes = int(round(count / 200.0)) minutes = max(minutes, 1) para += nodes.Text("Reading time: {} {}".format( minutes, 'minute' if minutes == 1 else 'minutes' )) node.replace_self([para])
def run(self): set_classes(self.options) rubric_text = self.arguments[0] textnodes, messages = self.state.inline_text(rubric_text, self.lineno) rubric = nodes.rubric(rubric_text, '', *textnodes, **self.options) self.add_name(rubric) return [rubric] + messages
def apply_source_workaround(node): # workaround: nodes.term have wrong rawsource if classifier is specified. # The behavior of docutils-0.11, 0.12 is: # * when ``term text : classifier1 : classifier2`` is specified, # * rawsource of term node will have: ``term text : classifier1 : classifier2`` # * rawsource of classifier node will be None if isinstance(node, nodes.classifier) and not node.rawsource: definition_list_item = node.parent node.source = definition_list_item.source node.line = definition_list_item.line - 1 node.rawsource = node.astext() # set 'classifier1' (or 'classifier2') if isinstance(node, nodes.term): # strip classifier from rawsource of term for classifier in reversed(node.parent.traverse(nodes.classifier)): node.rawsource = re.sub( '\s*:\s*%s' % re.escape(classifier.astext()), '', node.rawsource) # workaround: recommonmark-0.2.0 doesn't set rawsource attribute if not node.rawsource: node.rawsource = node.astext() if node.source and node.rawsource: return # workaround: docutils-0.10.0 or older's nodes.caption for nodes.figure # and nodes.title for nodes.admonition doesn't have source, line. # this issue was filed to Docutils tracker: # sf.net/tracker/?func=detail&aid=3599485&group_id=38414&atid=422032 # sourceforge.net/p/docutils/patches/108/ if (isinstance(node, ( nodes.caption, nodes.title, nodes.rubric, nodes.line, ))): node.source = find_source_node(node) node.line = 0 # need fix docutils to get `node.line` return