本文整理汇总了Python中docutils.nodes.admonition方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.admonition方法的具体用法?Python nodes.admonition怎么用?Python nodes.admonition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.admonition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import admonition [as 别名]
def run(self):
set_classes(self.options)
self.assert_has_content()
text = '\n'.join(self.content)
admonition_node = self.node_class(text, **self.options)
self.add_name(admonition_node)
if self.node_class is nodes.admonition:
title_text = self.arguments[0]
textnodes, messages = self.state.inline_text(title_text,
self.lineno)
title = nodes.title(title_text, '', *textnodes)
title.source, title.line = (
self.state_machine.get_source_and_line(self.lineno))
admonition_node += title
admonition_node += messages
if not 'classes' in self.options:
admonition_node['classes'] += ['admonition-' +
nodes.make_id(title_text)]
self.state.nested_parse(self.content, self.content_offset,
admonition_node)
return [admonition_node]
示例2: visit_admonition
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import admonition [as 别名]
def visit_admonition(self, node, name=None):
#
# Make admonitions a simple block quote
# with a strong heading
#
# Using .IP/.RE doesn't preserve indentation
# when admonitions contain bullets, literal,
# and/or block quotes.
#
if name:
# .. admonition:: has no name
self.body.append('.sp\n')
name = '%s%s:%s\n' % (
self.defs['strong'][0],
self.language.labels.get(name, name).upper(),
self.defs['strong'][1],
)
self.body.append(name)
self.visit_block_quote(node)
示例3: visit_title
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import admonition [as 别名]
def visit_title(self, node):
if isinstance(node.parent, nodes.topic):
self.body.append(self.defs['topic-title'][0])
elif isinstance(node.parent, nodes.sidebar):
self.body.append(self.defs['sidebar-title'][0])
elif isinstance(node.parent, nodes.admonition):
self.body.append('.IP "')
elif self.section_level == 0:
self._docinfo['title'] = node.astext()
# document title for .TH
self._docinfo['title_upper'] = node.astext().upper()
raise nodes.SkipNode
elif self.section_level == 1:
self.body.append('.SH %s\n' % self.deunicode(node.astext().upper()))
raise nodes.SkipNode
else:
self.body.append('.SS ')
示例4: visit_admonition
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import admonition [as 别名]
def visit_admonition(self, node, name=None):
#
# Make admonitions a simple block quote
# with a strong heading
#
# Using .IP/.RE doesn't preserve indentation
# when admonitions contain bullets, literal,
# and/or block quotes.
#
if name:
# .. admonition:: has no name
self.body.append('.sp\n')
name = '%s%s:%s\n' % (
self.defs['strong'][0],
self.language.labels.get(name, name).upper(),
self.defs['strong'][1],
)
self.body.append(name)
self.visit_block_quote(node)
示例5: 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)
示例6: depart_title
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import admonition [as 别名]
def depart_title(self, node):
if isinstance(node.parent, nodes.admonition):
self.body.append('"')
self.body.append('\n')