本文整理汇总了Python中docutils.nodes.Admonition方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.Admonition方法的具体用法?Python nodes.Admonition怎么用?Python nodes.Admonition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.Admonition方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def run(self):
env = self.state.document.settings.env
targetid = "tag-%d" % env.new_serialno('tag')
targetnode = nodes.target('', '', ids=[targetid])
# The tags fetched from the custom directive are one piece of text
# sitting in self.content[0]
taggs = self.content[0].split(", ")
links = []
for tagg in taggs:
# Create Sphinx doc refs of format :ref:`Tagname<Tagname>`
link = ":ref:`" + tagg + "<" + tagg + ">`"
links.append(link)
# Put links back in a single comma-separated string together
linkjoin = ", ".join(links)
# Replace content[0] with hyperlinks to display in admonition
self.content[0] = linkjoin
ad = Admonition(self.name, [_('Tags')], self.options,
self.content, self.lineno, self.content_offset,
self.block_text, self.state, self.state_machine)
return [targetnode] + ad.run()
示例2: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def run(self):
return [Todolist('')]
# Admonition classes are like notes or warnings
示例3: visit_title
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def visit_title(self, node):
if isinstance(node.parent, nodes.Admonition):
self.add_text(node.astext()+': ')
raise nodes.SkipNode
self.new_state(0)
示例4: apply
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def apply(self):
language = languages.get_language(self.document.settings.language_code,
self.document.reporter)
for node in self.document.traverse(nodes.Admonition):
node_name = node.__class__.__name__
# Set class, so that we know what node this admonition came from.
node['classes'].append(node_name)
if not isinstance(node, nodes.admonition):
# Specific admonition. Transform into a generic admonition.
admonition = nodes.admonition(node.rawsource, *node.children,
**node.attributes)
title = nodes.title('', language.labels[node_name])
admonition.insert(0, title)
node.replace_self(admonition)
示例5: visit_title
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def visit_title(self, node):
"""Only 6 section levels are supported by HTML."""
check_id = 0 # TODO: is this a bool (False) or a counter?
close_tag = '</p>\n'
if isinstance(node.parent, nodes.topic):
self.body.append(
self.starttag(node, 'p', '', CLASS='topic-title first'))
elif isinstance(node.parent, nodes.sidebar):
self.body.append(
self.starttag(node, 'p', '', CLASS='sidebar-title'))
elif isinstance(node.parent, nodes.Admonition):
self.body.append(
self.starttag(node, 'p', '', CLASS='admonition-title'))
elif isinstance(node.parent, nodes.table):
self.body.append(
self.starttag(node, 'caption', ''))
close_tag = '</caption>\n'
elif isinstance(node.parent, nodes.document):
self.body.append(self.starttag(node, 'h1', '', CLASS='title'))
close_tag = '</h1>\n'
self.in_document_title = len(self.body)
else:
assert isinstance(node.parent, nodes.section)
h_level = self.section_level + self.initial_header_level - 1
atts = {}
if (len(node.parent) >= 2 and
isinstance(node.parent[1], nodes.subtitle)):
atts['CLASS'] = 'with-subtitle'
self.body.append(
self.starttag(node, 'h%s' % h_level, '', **atts))
atts = {}
if node.hasattr('refid'):
atts['class'] = 'toc-backref'
atts['href'] = '#' + node['refid']
if atts:
self.body.append(self.starttag({}, 'a', '', **atts))
close_tag = '</a></h%s>\n' % (h_level)
else:
close_tag = '</h%s>\n' % (h_level)
self.context.append(close_tag)
示例6: visit_paragraph
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def visit_paragraph(self, node):
if not isinstance(node.parent, nodes.Admonition) or \
isinstance(node.parent, addnodes.seealso):
self.new_state(0)
示例7: depart_paragraph
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def depart_paragraph(self, node):
if not isinstance(node.parent, nodes.Admonition) or \
isinstance(node.parent, addnodes.seealso):
self.end_state()
示例8: visit_title
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def visit_title(self, node):
if isinstance(node.parent, nodes.Admonition):
self.add_text(node.astext() + ': ')
raise nodes.SkipNode
self.new_state(0)
示例9: visit_paragraph
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import Admonition [as 别名]
def visit_paragraph(self, node):
if not isinstance(node.parent, nodes.Admonition) or \
isinstance(node.parent, addnodes.seealso):
self.new_state(0)