本文整理汇总了Python中docutils.nodes.caption方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.caption方法的具体用法?Python nodes.caption怎么用?Python nodes.caption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.caption方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _container_wrapper
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def _container_wrapper(directive, literal_node, caption):
container_node = nodes.container('', literal_block=True,
classes=['literal-block-wrapper'])
parsed = nodes.Element()
directive.state.nested_parse(StringList([caption], source=''),
directive.content_offset, parsed)
if isinstance(parsed[0], nodes.system_message): # pragma: no cover
# TODO: Figure out if this is really possible and how to produce
# it in a test case.
msg = 'Invalid caption: %s' % parsed[0].astext()
raise ValueError(msg)
assert isinstance(parsed[0], nodes.Element)
caption_node = nodes.caption(parsed[0].rawsource, '',
*parsed[0].children)
caption_node.source = literal_node.source
caption_node.line = literal_node.line
container_node += caption_node
container_node += literal_node
return container_node
示例2: assert_output
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def assert_output(self, doctree, output, **kwargs):
__tracebackhide__ = True
literal = doctree.next_node(literal_block)
self.assertTrue(literal)
self.assertEqual(literal.astext(), output)
if 'caption' in kwargs:
caption_node = doctree.next_node(caption)
self.assertTrue(caption_node)
self.assertEqual(caption_node.astext(), kwargs.get('caption'))
if 'name' in kwargs:
if 'caption' in kwargs:
container_node = doctree.next_node(container)
self.assertTrue(container_node)
self.assertIn(kwargs.get('name'), container_node.get('ids'))
else:
self.assertIn(kwargs.get('name'), literal.get('ids'))
示例3: test_caption_option
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def test_caption_option(self):
directives.setup(format='SVG', outputdir=self.tmpdir)
text = (".. rackdiag::\n"
" :caption: hello world\n"
"\n"
" 1: server\n"
" 2: database\n")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.figure, type(doctree[0]))
self.assertEqual(2, len(doctree[0]))
self.assertEqual(nodes.image, type(doctree[0][0]))
self.assertEqual(nodes.caption, type(doctree[0][1]))
self.assertEqual(1, len(doctree[0][1]))
self.assertEqual(nodes.Text, type(doctree[0][1][0]))
self.assertEqual('hello world', doctree[0][1][0])
示例4: test_caption_option_and_align_option
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def test_caption_option_and_align_option(self):
directives.setup(format='SVG', outputdir=self.tmpdir)
text = (".. rackdiag::\n"
" :align: left\n"
" :caption: hello world\n"
"\n"
" 1: server\n"
" 2: database\n")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.figure, type(doctree[0]))
self.assertEqual('left', doctree[0]['align'])
self.assertEqual(2, len(doctree[0]))
self.assertEqual(nodes.image, type(doctree[0][0]))
self.assertNotIn('align', doctree[0][0])
self.assertEqual(nodes.caption, type(doctree[0][1]))
self.assertEqual(1, len(doctree[0][1]))
self.assertEqual(nodes.Text, type(doctree[0][1][0]))
self.assertEqual('hello world', doctree[0][1][0])
示例5: test_caption_option_and_align_option
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def test_caption_option_and_align_option(self):
directives.setup(format='SVG', outputdir=self.tmpdir)
text = (".. packetdiag::\n"
" :align: left\n"
" :caption: hello world\n"
"\n"
" 1: server\n"
" 2: database\n")
doctree = publish_doctree(text)
self.assertEqual(1, len(doctree))
self.assertEqual(nodes.figure, type(doctree[0]))
self.assertEqual('left', doctree[0]['align'])
self.assertEqual(2, len(doctree[0]))
self.assertEqual(nodes.image, type(doctree[0][0]))
self.assertNotIn('align', doctree[0][0])
self.assertEqual(nodes.caption, type(doctree[0][1]))
self.assertEqual(1, len(doctree[0][1]))
self.assertEqual(nodes.Text, type(doctree[0][1][0]))
self.assertEqual('hello world', doctree[0][1][0])
示例6: figure_wrapper
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def figure_wrapper(directive, node, caption):
# type: (Directive, nodes.Node, unicode) -> nodes.figure
figure_node = nodes.figure('', node)
if 'align' in node:
figure_node['align'] = node.attributes.pop('align')
parsed = nodes.Element()
directive.state.nested_parse(ViewList([caption], source=''),
directive.content_offset, parsed)
caption_node = nodes.caption(parsed[0].rawsource, '',
*parsed[0].children)
caption_node.source = parsed[0].source
caption_node.line = parsed[0].line
figure_node += caption_node
return figure_node
示例7: open
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def open(self):
self._open = True
self._col_specs = []
self.caption = []
self._attrs = {}
self._in_head = False # maybe context with search
示例8: close
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def close(self):
self._open = False
self._col_specs = None
self.caption = []
self._attrs = {}
self.stubs = []
self.colwidths_auto = False
示例9: get_latex_type
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def get_latex_type(self):
if self._latex_type == 'longtable' and not self.caption:
# do not advance the "table" counter (requires "ltcaption" package)
return('longtable*')
return self._latex_type
示例10: get_caption
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def get_caption(self):
if not self.caption:
return ''
caption = ''.join(self.caption)
if 1 == self._translator.thead_depth():
return r'\caption{%s}\\' '\n' % caption
return r'\caption[]{%s (... continued)}\\' '\n' % caption
示例11: depart_table
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def depart_table(self, node):
# wrap content in the right environment:
content = self.out
self.pop_output_collector()
self.out.append('\n' + self.active_table.get_opening())
self.out += content
self.out.append(self.active_table.get_closing() + '\n')
self.active_table.close()
if len(self.table_stack)>0:
self.active_table = self.table_stack.pop()
# Insert hyperlabel after (long)table, as
# other places (beginning, caption) result in LaTeX errors.
if node.get('ids'):
self.out += self.ids_to_labels(node, set_anchor=False) + ['\n']
示例12: visit_target
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import caption [as 别名]
def visit_target(self, node):
# Skip indirect targets:
if ('refuri' in node # external hyperlink
or 'refid' in node # resolved internal link
or 'refname' in node): # unresolved internal link
## self.out.append('%% %s\n' % node) # for debugging
return
self.out.append('%\n')
# do we need an anchor (\phantomsection)?
set_anchor = not(isinstance(node.parent, nodes.caption) or
isinstance(node.parent, nodes.title))
# TODO: where else can/must we omit the \phantomsection?
self.out += self.ids_to_labels(node, set_anchor)