Python docutils.nodes.caption() Examples

The following are 30 code examples of docutils.nodes.caption(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module docutils.nodes , or try the search function .
Example #1
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 6 votes vote down vote up
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]) 
Example #2
Source File: __init__.py    From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 
Example #3
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 6 votes vote down vote up
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]) 
Example #4
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 6 votes vote down vote up
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]) 
Example #5
Source File: test_directive.py    From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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')) 
Example #6
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 5 votes vote down vote up
def test_figclass_option(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. rackdiag::\n"
                "   :caption: hello world\n"
                "   :figclass: baz\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(['baz'], doctree[0]['classes']) 
Example #7
Source File: __init__.py    From blackmamba with MIT License 5 votes vote down vote up
def close(self):
        self._open = False
        self._col_specs = None
        self.caption = []
        self._attrs = {}
        self.stubs = []
        self.colwidths_auto = False 
Example #8
Source File: __init__.py    From blackmamba with MIT License 5 votes vote down vote up
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 
Example #9
Source File: __init__.py    From blackmamba with MIT License 5 votes vote down vote up
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 
Example #10
Source File: __init__.py    From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def run(self):
        env = self.state.document.settings.env

        node = program_output()
        node.line = self.lineno
        node['command'] = self.arguments[0]

        if self.name == 'command-output':
            node['show_prompt'] = True
        else:
            node['show_prompt'] = 'prompt' in self.options

        node['hide_standard_error'] = 'nostderr' in self.options
        node['extraargs'] = self.options.get('extraargs', '')
        _, cwd = env.relfn2path(self.options.get('cwd', '/'))
        node['working_directory'] = cwd
        node['use_shell'] = 'shell' in self.options
        node['returncode'] = self.options.get('returncode', 0)
        if 'ellipsis' in self.options:
            node['strip_lines'] = self.options['ellipsis']
        if 'caption' in self.options:
            caption = self.options['caption'] or self.arguments[0]
            node = _container_wrapper(self, node, caption)

        self.add_name(node)
        return [node] 
Example #11
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 5 votes vote down vote up
def test_figwidth_option2(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. packetdiag::\n"
                "   :caption: hello world\n"
                "   :figwidth: image\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('200px', doctree[0]['width']) 
Example #12
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 5 votes vote down vote up
def test_figwidth_option1(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. packetdiag::\n"
                "   :caption: hello world\n"
                "   :figwidth: 100\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('100px', doctree[0]['width']) 
Example #13
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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'] 
Example #14
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 5 votes vote down vote up
def test_figwidth_option2(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. rackdiag::\n"
                "   :caption: hello world\n"
                "   :figwidth: image\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('256px', doctree[0]['width']) 
Example #15
Source File: test_rst_directives.py    From nwdiag with Apache License 2.0 5 votes vote down vote up
def test_figwidth_option1(self):
        directives.setup(format='SVG', outputdir=self.tmpdir)
        text = (".. rackdiag::\n"
                "   :caption: hello world\n"
                "   :figwidth: 100\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('100px', doctree[0]['width']) 
Example #16
Source File: test_directive.py    From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_caption(self):
        self.assert_output(self.doctree, 'spam', caption='mycaption')
        self.assert_cache(self.app, 'echo spam', 'spam') 
Example #17
Source File: test_directive.py    From sphinxcontrib-programoutput with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_caption_default(self):
        self.assert_output(self.doctree, 'spam', caption='echo spam')
        self.assert_cache(self.app, 'echo spam', 'spam') 
Example #18
Source File: __init__.py    From aws-extender with MIT License 5 votes vote down vote up
def open(self):
        self._open = True
        self._col_specs = []
        self.caption = []
        self._attrs = {}
        self._in_head = False # maybe context with search 
Example #19
Source File: __init__.py    From blackmamba with MIT License 5 votes vote down vote up
def open(self):
        self._open = True
        self._col_specs = []
        self.caption = []
        self._attrs = {}
        self._in_head = False # maybe context with search 
Example #20
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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) 
Example #21
Source File: __init__.py    From aws-extender with MIT License 5 votes vote down vote up
def close(self):
        self._open = False
        self._col_specs = None
        self.caption = []
        self._attrs = {}
        self.stubs = []
        self.colwidths_auto = False 
Example #22
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def visit_caption(self, node):
        self.out.append('\n\\caption{') 
Example #23
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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 
Example #24
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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 
Example #25
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def open(self):
        self._open = True
        self._col_specs = []
        self.caption = []
        self._attrs = {}
        self._in_head = False # maybe context with search 
Example #26
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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) 
Example #27
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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'] 
Example #28
Source File: symbolator_sphinx.py    From symbolator with MIT License 5 votes vote down vote up
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 
Example #29
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
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 
Example #30
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def close(self):
        self._open = False
        self._col_specs = None
        self.caption = []
        self._attrs = {}
        self.stubs = []
        self.colwidths_auto = False