Example #1
0
    def run(self):
        """
        Generate the definition list that displays the actual references.
        """
        env = self.state.document.settings.env
        keys = env.domaindata['cite']['keys']
        env.domaindata['cite']['refdoc'] = env.docname

        citations = env.domains['cite'].citations

        tbody = nodes.tbody('')
        for i, key in enumerate(keys):
            row = nodes.row('')
            nid = "citation-%s" % nodes.make_id(key)
            row['classes'].append('footnote')
            row['ids'].append(nid)
            row['names'].append(nid)

            numcol = nodes.entry('', nodes.paragraph('', '[%d]' % (i + 1)))
            definition = self.get_reference_node(citations.get(key))
            refcol = nodes.entry('', nodes.paragraph('', '', definition))
            row.extend([numcol, refcol])

            tbody.append(row)

        table_spec_node = addnodes.tabular_col_spec()
        table_spec_node['spec'] = 'cl'

        node = nodes.table(
            '', table_spec_node,
            nodes.tgroup('', nodes.colspec(colwidth=10, classes=['label']),
                         nodes.colspec(colwidth=90), tbody))

        return [node]
Example #2
0
    def _get_table_spec(self):
        ncols = self.f2x_ncols()
        column_titles = self.f2x_get_title()

        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = r'\X{1}{2}' * ncols

        table_wrap = autosummary_table('')
        table_layout = nodes.table('', classes=['longtable'])
        table_group = nodes.tgroup('', cols=ncols)
        table_body = nodes.tbody('')

        table_wrap.append(table_layout)
        table_layout.append(table_group)

        for width in self.f2x_get_width():
            table_group.append(nodes.colspec('', colwidth=width))

        if self.options.get('showheader', False) and column_titles is not None:
            table_head = nodes.thead('')
            table_group.append(table_head)
            self._append_row(table_head, column_titles)

        table_group.append(table_body)

        return table_spec, table_wrap, table_body
    def get_tablespec(self):
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)
        return table, table_spec, append_row
    def run(self):
        label = self.options.get('label', None)
        spec = self.options.get('spec', None)
        caption = self.options.get('caption', None)
        alt = self.options.get('alt', None)
        nofig = 'nofig' in self.options

        figtable_node = figtable('', ids=[label] if label is not None else [])
        figtable_node['nofig'] = nofig

        if spec is not None:
            table_spec_node = addnodes.tabular_col_spec()
            table_spec_node['spec'] = spec
            figtable_node.append(table_spec_node)

        node = nodes.Element()
        self.state.nested_parse(self.content, self.content_offset, node)
        tablenode = node[0]
        if alt is not None:
            tablenode['alt'] = alt
        figtable_node.append(tablenode)

        if caption is not None:
            caption_node = nodes.caption('', '', nodes.Text(caption))
            figtable_node.append(caption_node)

        if label is not None:
            targetnode = nodes.target('', '', ids=[label])
            figtable_node.append(targetnode)

        return [figtable_node]
    def get_tablespec(self):
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        return table, table_spec, append_row
Example #6
0
    def run(self):
        label = self.options.get('label', None)
        spec = self.options.get('spec', None)
        caption = self.options.get('caption', None)
        alt = self.options.get('alt', None)
        nofig = 'nofig' in self.options
        loc = self.options.get('loc', None)
        
        figtable_node = figtable('', ids=[label] if label is not None else [])
        figtable_node['nofig'] = nofig
        
        if spec is not None:
            table_spec_node = addnodes.tabular_col_spec()
            table_spec_node['spec'] = spec
            figtable_node.append(table_spec_node)
        
        node = nodes.Element()
        self.state.nested_parse(self.content, self.content_offset, node)
        tablenode = node[0]
        if alt is not None:
            tablenode['alt'] = alt
        figtable_node.append(tablenode)
        
        if caption is not None:
            caption_node = nodes.caption('', '', nodes.Text(caption))
            figtable_node.append(caption_node)
        
        if label is not None:
            targetnode = nodes.target('', '', ids=[label])
            figtable_node.append(targetnode)

        if loc is not None:
            figtable_node['loc'] = '[' + loc + ']'

        return [figtable_node]
Example #7
0
    def get_table(self, items: List[Tuple[str, str, str,
                                          str]]) -> List[nodes.Node]:
        """
		Generate a proper list of table nodes for autosummary:: directive.

		:param items: A a list produced by :meth:`~.get_items`.
		"""
        table_spec = addnodes.tabular_col_spec()
        # table_spec['spec'] = r'\Xx{1}{3}\Xx{2}{3}'
        # table_spec['spec'] = r'\Xx{3}{8}\Xx{5}{8}'
        # table_spec['spec'] = r'\Xx{7}{16}\Xx{9}{16}'

        widths = chain.from_iterable(
            getattr(self.state.document, "autosummary_widths",
                    ((1, 2), (1, 2))))
        table_spec["spec"] = r'\Xx{{{}}}{{{}}}\Xx{{{}}}{{{}}}'.format(*widths)

        table = autosummary_table('')
        real_table = nodes.table('', classes=["longtable"])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts: str) -> None:
            row = nodes.row('')
            source, line = self.state_machine.get_source_and_line()
            for text in column_texts:
                node = nodes.paragraph('')
                vl = StringList()
                vl.append(text, "%s:%d:<autosummary>" % (source, line))
                with switch_source_input(self.state, vl):
                    self.state.nested_parse(vl, 0, node)
                    try:
                        if isinstance(node[0], nodes.paragraph):
                            node = node[0]
                    except IndexError:
                        pass
                    row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = "obj"
            if "nosignatures" not in self.options:
                col1 = ":{}:`{} <{}>`\\ {}".format(
                    qualifier, name, real_name,
                    rst.escape(sig).replace('(', "(​"))
            else:
                col1 = f":{qualifier}:`{name} <{real_name}>`"
            col2 = summary
            append_row(col1, col2)

        return [table_spec, table]
Example #8
0
    def get_table(self, items_set):
        """Generate a proper list of table nodes for errorsummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=3)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=70))
        group.append(nodes.colspec('', colwidth=20))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        col1 = u"**Name**"
        col2 = u"**Code**"
        col3 = u"**Message**"
        append_row(col1, col2, col3)

        for class_name, items in sorted(items_set.items()):
            for name, sig, summary, real_name, code in items:
                if 'nosignatures' not in self.options:
                    col1 = '_%s' % name
                col2 = '{}'.format(code)
                translated = translate(summary, "ru") if summary else ""
                if translated != summary:
                    col3 = u"{} / {}".format(translated, summary)
                else:
                    col3 = summary

                append_row(col1, col2, col3)

        return [table_spec, table]
Example #9
0
    def get_table(self, items_set):
        """Generate a proper list of table nodes for errorsummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=3)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=70))
        group.append(nodes.colspec('', colwidth=20))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        col1 = u"**Name**"
        col2 = u"**Code**"
        col3 = u"**Message**"
        append_row(col1, col2, col3)

        for class_name, items in sorted(items_set.items()):
            for name, sig, summary, real_name, code in items:
                if 'nosignatures' not in self.options:
                    col1 = '_%s' % name
                col2 = '{}'.format(code)
                translated = translate(summary, "ru") if summary else ""
                if translated != summary:
                    col3 = u"{} / {}".format(translated, summary)
                else:
                    col3 = summary

                append_row(col1, col2, col3)

        return [table_spec, table]
Example #10
0
        def format_table(self, items):
            """Generate a proper list of table nodes for autosummary:: directive.

            *items* is a list produced by :meth:`get_items`.
            """
            table_spec = addnodes.tabular_col_spec()
            table_spec["spec"] = r"\X{1}{2}\X{1}{2}"

            table = autosummary_table("")
            real_table = nodes.table("", classes=["longtable"])
            table.append(real_table)
            group = nodes.tgroup("", cols=2)
            real_table.append(group)
            group.append(nodes.colspec("", colwidth=10))
            group.append(nodes.colspec("", colwidth=90))
            body = nodes.tbody("")
            group.append(body)

            def append_row(*column_texts: str) -> None:
                row = nodes.row("")
                source, line = self.state_machine.get_source_and_line()
                for text in column_texts:
                    node = nodes.paragraph("")
                    vl = StringList()
                    vl.append(text, "%s:%d:<autosummary>" % (source, line))
                    with switch_source_input(self.state, vl):
                        self.state.nested_parse(vl, 0, node)
                        try:
                            if isinstance(node[0], nodes.paragraph):
                                node = node[0]
                        except IndexError:
                            pass
                        row.append(nodes.entry("", node))
                body.append(row)

            for prefix, name, sig, summary, real_name in items:
                qualifier = "any"  # <== Only thing changed from autosummary version
                if "nosignatures" not in self.options:
                    col1 = "%s:%s:`%s <%s>`\\ %s" % (
                        prefix,
                        qualifier,
                        name,
                        real_name,
                        rst.escape(sig),
                    )
                else:
                    col1 = "%s:%s:`%s <%s>`" % (prefix, qualifier, name,
                                                real_name)
                col2 = summary
                append_row(col1, col2)

            return [table_spec, table]
Example #11
0
    def get_table(self, items):
        # type: (List[Tuple[unicode, unicode, unicode, unicode]]) -> List[Union[addnodes.tabular_col_spec, autosummary_table]]  # NOQA
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = r'\X{1}{2}\X{1}{2}'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            # type: (unicode) -> None
            row = nodes.row('')
            source, line = self.state_machine.get_source_and_line()
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '%s:%d:<autosummary>' % (source, line))
                with switch_source_input(self.state, vl):
                    self.state.nested_parse(vl, 0, node)
                    try:
                        if isinstance(node[0], nodes.paragraph):
                            node = node[0]
                    except IndexError:
                        pass
                    row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\\ %s' % (
                    qualifier, name, real_name, rst.escape(sig)
                )  # type: unicode  # NOQA
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            append_row(col1, col2)

        return [table_spec, table]
Example #12
0
    def get_table(self):
        """docstring for get_table"""
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)
        return table_spec, table, body
Example #13
0
    def get_table(self, items):
        """
        Subclass to get support for `hidesummary` as options
        to enable displaying the short summary in the table
        """
        hidesummary = 'hidesummary' in self.options
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name,
                                              rst.escape(sig))
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            if hidesummary:
                append_row(col1)
            else:
                append_row(col1, col2)

        return [table_spec, table]
Example #14
0
    def get_table(self, items):
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'LL'

        table = autosummary_table('')
        real_table = nodes.table('')

        if "title" in self.options:
            title_node = self.make_title(self.options["title"])
            real_table.insert(0, title_node)
            
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<doxybridge-autosummary>')
                self.sphinx_directive.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = self.get_qualifier(name)
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig)
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            append_row(col1, col2)

        return [table_spec, table]
Example #15
0
    def get_table(self, items):
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'LL'

        table = autosummary_table('')
        real_table = nodes.table('')

        if "title" in self.options:
            title_node = self.make_title(self.options["title"])
            real_table.insert(0, title_node)

        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<doxybridge-autosummary>')
                self.sphinx_directive.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = self.get_qualifier(name)
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig)
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            append_row(col1, col2)

        return [table_spec, table]
Example #16
0
    def get_table(self, items):
        """
        Subclass to get support for `hidesummary` as options
        to enable displaying the short summary in the table
        """
        hidesummary = 'hidesummary' in self.options
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'p{0.5\linewidth}p{0.5\linewidth}'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, rst.escape(sig))
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            if hidesummary:
                append_row(col1)
            else:
                append_row(col1, col2)

        return [table_spec, table]
Example #17
0
    def get_table(self, items):
        # type: (List[Tuple[unicode, unicode, unicode, unicode]]) -> List[Union[addnodes.tabular_col_spec, autosummary_table]]  # NOQA
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = r'\X{1}{2}\X{1}{2}'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            # type: (unicode) -> None
            row = nodes.row('')
            source, line = self.state_machine.get_source_and_line()
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '%s:%d:<autosummary>' % (source, line))
                with switch_source_input(self.state, vl):
                    self.state.nested_parse(vl, 0, node)
                    try:
                        if isinstance(node[0], nodes.paragraph):
                            node = node[0]
                    except IndexError:
                        pass
                    row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\\ %s' % (qualifier, name, real_name, rst.escape(sig))  # type: unicode  # NOQA
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            col2 = summary
            append_row(col1, col2)

        return [table_spec, table]
    def get_table(self, items):
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('')
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=0))
        group.append(nodes.colspec('', colwidth=100))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name, prefix in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig)
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            if prefix:
                prefix = "*%s*" % prefix

            append_row(prefix, col1)

        return [table_spec, table]
    def get_table(self, items):
        """Generate a proper list of table nodes for autosummary:: directive.

        *items* is a list produced by :meth:`get_items`.
        """
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = 'll'

        table = autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('')
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=0))
        group.append(nodes.colspec('', colwidth=100))
        body = nodes.tbody('')
        group.append(body)

        def append_row(*column_texts):
            row = nodes.row('')
            for text in column_texts:
                node = nodes.paragraph('')
                vl = ViewList()
                vl.append(text, '<autosummary>')
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry('', node))
            body.append(row)

        for name, sig, summary, real_name, prefix in items:
            qualifier = 'obj'
            if 'nosignatures' not in self.options:
                col1 = ':%s:`%s <%s>`\ %s' % (qualifier, name, real_name, sig)
            else:
                col1 = ':%s:`%s <%s>`' % (qualifier, name, real_name)
            if prefix:
                prefix = "*%s*" % prefix

            append_row(prefix, col1)

        return [table_spec, table]
Example #20
0
    def _get_table(self, objects):
        table_spec = addnodes.tabular_col_spec()
        table_spec['spec'] = r'p{0.5\linewidth}p{0.5\linewidth}'

        table = sphinx.ext.autosummary.autosummary_table('')
        real_table = nodes.table('', classes=['longtable'])
        table.append(real_table)
        group = nodes.tgroup('', cols=2)
        real_table.append(group)
        group.append(nodes.colspec('', colwidth=10))
        group.append(nodes.colspec('', colwidth=90))
        body = nodes.tbody('')
        group.append(body)

        for obj in objects:
            body.append(self._get_row(obj))

        return [table_spec, table]
Example #21
0
    def _get_table(self, objects):
        table_spec = addnodes.tabular_col_spec()
        table_spec["spec"] = r"p{0.5\linewidth}p{0.5\linewidth}"

        table = sphinx.ext.autosummary.autosummary_table("")
        real_table = nodes.table("", classes=["longtable"])
        table.append(real_table)
        group = nodes.tgroup("", cols=2)
        real_table.append(group)
        group.append(nodes.colspec("", colwidth=10))
        group.append(nodes.colspec("", colwidth=90))
        body = nodes.tbody("")
        group.append(body)

        for obj in objects:
            body.append(self._get_row(obj))

        return [table_spec, table]
Example #22
0
    def _get_table(self, objects):
        table_spec = addnodes.tabular_col_spec()
        table_spec["spec"] = r"p{0.5\linewidth}p{0.5\linewidth}"

        table = sphinx.ext.autosummary.autosummary_table("")
        real_table = nodes.table("", classes=["longtable"])
        table.append(real_table)
        group = nodes.tgroup("", cols=2)
        real_table.append(group)
        group.append(nodes.colspec("", colwidth=10))
        group.append(nodes.colspec("", colwidth=90))
        body = nodes.tbody("")
        group.append(body)

        for obj in objects:
            body.append(self._get_row(obj))

        return [table_spec, table]
    def run(self):
        label = self.options.get('label', None)
        spec = self.options.get('spec', None)
        caption = self.options.get('caption', None)
        alt = self.options.get('alt', None)
        nofig = 'nofig' in self.options

        figtable_node = figtable('', ids=[label] if label is not None else [])
        figtable_node['nofig'] = nofig

        if spec is not None:
            table_spec_node = addnodes.tabular_col_spec()
            table_spec_node['spec'] = spec
            figtable_node.append(table_spec_node)

        node = nodes.Element()
        self.state.nested_parse(self.content, self.content_offset, node)
        tablenode = node[0]
        if alt is not None:
            tablenode['alt'] = alt
        figtable_node.append(tablenode)

        if caption is not None:
            # Original SphinxTr source:
            # caption_node = nodes.caption('', '', nodes.Text(caption))
            # figtable_node.append(caption_node)

            # Modified: Support for parsing content of captions
            caption_node = nodes.Element()
            self.state.nested_parse(docutils.statemachine.StringList([caption]), self.content_offset, caption_node)
            if isinstance(caption_node[0], nodes.paragraph):
                caption = nodes.caption(caption_node[0].rawsource, '', *caption_node[0].children)
                figtable_node += caption

        if label is not None:
            targetnode = nodes.target('', '', ids=[label])
            figtable_node.append(targetnode)

        return [figtable_node]
Example #24
0
  def run(self):
    """
    Generate the definition list that displays the actual references.
    """
    env = self.state.document.settings.env
    keys = env.domaindata['cite']['keys']
    env.domaindata['cite']['refdoc'] = env.docname

    citations = env.domains['cite'].citations

    # TODO: implement
    #env.domaindata['cite']['refdocs'][env.docname] = Citations(env, path)

    tbody = nodes.tbody('')
    for i, key in enumerate(keys):
        row = nodes.row('')
        nid = "citation-%s" % nodes.make_id(key)
        row['classes'].append('footnote')
        row['ids'].append(nid)
        row['names'].append(nid)

        numcol = nodes.entry('', nodes.paragraph('', '[%d]' % (i + 1)))
        definition = self.get_reference_node(citations.get(key))
        refcol = nodes.entry('', nodes.paragraph('', '', definition))
        row.extend([numcol, refcol])

        tbody.append(row)

    table_spec_node = addnodes.tabular_col_spec()
    table_spec_node['spec'] = 'cl'

    node = nodes.table('',
                       table_spec_node,
                       nodes.tgroup('',
                                    nodes.colspec(colwidth=10, classes=['label']),
                                    nodes.colspec(colwidth=90),
                                    tbody))

    return [node]
Example #25
0
    def run(self):
        """
    Generate the definition list that displays the actual references.
    """
        env = self.state.document.settings.env
        keys = env.domaindata["cite"]["keys"]
        env.domaindata["cite"]["refdoc"] = env.docname

        citations = env.domains["cite"].citations

        # TODO: implement
        # env.domaindata['cite']['refdocs'][env.docname] = Citations(env, path)

        tbody = nodes.tbody("")
        for i, key in enumerate(keys):
            row = nodes.row("")
            nid = "citation-%s" % nodes.make_id(key)
            row["classes"].append("footnote")
            row["ids"].append(nid)
            row["names"].append(nid)

            numcol = nodes.entry("", nodes.paragraph("", "[%d]" % (i + 1)))
            definition = self.get_reference_node(citations.get(key))
            refcol = nodes.entry("", nodes.paragraph("", "", definition))
            row.extend([numcol, refcol])

            tbody.append(row)

        table_spec_node = addnodes.tabular_col_spec()
        table_spec_node["spec"] = "cl"

        node = nodes.table(
            "",
            table_spec_node,
            nodes.tgroup("", nodes.colspec(colwidth=10, classes=["label"]), nodes.colspec(colwidth=90), tbody),
        )

        return [node]
Example #26
0
        def format_packages_table(self, packages: dict[str, Any],
                                  columns: tuple[str]) -> list[Any]:
            table_spec = addnodes.tabular_col_spec()
            table_spec["spec"] = r"\X{1}{2}\X{1}{2}"

            table = nodes.table("", classes=["longtable"])

            group = nodes.tgroup("", cols=len(columns))
            group.extend([nodes.colspec("", colwidth=100) for _ in columns])
            table.append(group)

            thead = nodes.thead()
            row = nodes.row()
            for column in columns:
                entry = nodes.entry()
                entry += nodes.paragraph(text=column.capitalize())
                row += entry

            thead.append(row)
            group += thead

            rows = []
            for name, pkg_info in packages.items():
                row = nodes.row()
                rows.append(row)
                for column in columns:
                    value = pkg_info[column]
                    entry = nodes.entry()
                    entry += nodes.paragraph(text=value)
                    row += entry

            tbody = nodes.tbody()
            tbody.extend(rows)
            group += tbody

            return [table_spec, table]
Example #27
0
 def run(self):
     node = addnodes.tabular_col_spec()
     node['spec'] = self.arguments[0]
     set_source_info(self, node)
     return [node]
Example #28
0
 def run(self):
     node = addnodes.tabular_col_spec()
     node['spec'] = self.arguments[0]
     set_source_info(self, node)
     return [node]
    def get_table(self, items: List[Tuple[str, str, str, str,
                                          str]]) -> List[Node]:
        """Generate a proper list of table nodes for autosummary:: directive.
        *items* is a list produced by :meth:`get_items`.
        """

        has_config_type = any([item[-1] is not None for item in items])
        if has_config_type:
            n_cols = 3
        else:
            n_cols = 2

        table_spec = addnodes.tabular_col_spec()
        table_spec["spec"] = r"\X{1}{2}\X{1}{2}"

        table = autosummary_table("")
        real_table = nodes.table("", classes=["longtable"])
        table.append(real_table)
        group = nodes.tgroup("", cols=n_cols)
        real_table.append(group)
        group.append(nodes.colspec("", colwidth=10))
        if has_config_type:
            group.append(nodes.colspec("", colwidth=10))
        group.append(nodes.colspec("", colwidth=90))

        head = nodes.thead("")
        cols = ["Class/method name", "type", "Summary"]
        if not has_config_type:
            del cols[1]
        row = nodes.row("")
        source, line = self.state_machine.get_source_and_line()
        for text in cols:
            node = nodes.paragraph("")
            vl = StringList()
            vl.append(text, "%s:%d:<autosummary>" % (source, line))
            with switch_source_input(self.state, vl):
                self.state.nested_parse(vl, 0, node)
                try:
                    if isinstance(node[0], nodes.paragraph):
                        node = node[0]
                except IndexError:
                    pass
                row.append(nodes.entry("", node))
        head.append(row)
        group.append(head)

        body = nodes.tbody("")
        group.append(body)

        def append_row(*column_texts: str) -> None:
            row = nodes.row("")
            source, line = self.state_machine.get_source_and_line()
            for text in column_texts:
                node = nodes.paragraph("")
                vl = StringList()
                vl.append(text, "%s:%d:<autosummary>" % (source, line))
                with switch_source_input(self.state, vl):
                    self.state.nested_parse(vl, 0, node)
                    try:
                        if isinstance(node[0], nodes.paragraph):
                            node = node[0]
                    except IndexError:
                        pass
                    row.append(nodes.entry("", node))
            body.append(row)

        for name, sig, summary, real_name, config_type in items:
            qualifier = "obj"
            if "nosignatures" not in self.options:
                col1 = ":%s:`%s <%s>`\\ %s" % (
                    qualifier,
                    name,
                    real_name,
                    rst.escape(sig),
                )
            else:
                col1 = ":%s:`%s <%s>`" % (qualifier, name, real_name)
            col2 = summary
            if has_config_type:
                col3 = config_type if config_type else ""
                append_row(col1, col3, col2)
            else:
                append_row(col1, col2)
        return [table_spec, table]
Example #30
0
 def run(self):
     node = addnodes.tabular_col_spec()
     node['spec'] = self.arguments[0]
     return [node]
Example #31
0
 def run(self):
     # type: () -> List[nodes.Node]
     node = addnodes.tabular_col_spec()
     node['spec'] = self.arguments[0]
     self.set_source_info(node)
     return [node]
Example #32
0
def tabularcolumns_directive(name, arguments, options, content, lineno,
                             content_offset, block_text, state, state_machine):
    # support giving explicit tabulary column definition to latex
    node = addnodes.tabular_col_spec()
    node['spec'] = arguments[0]
    return [node]
Example #33
0
def tabularcolumns_directive(name, arguments, options, content, lineno,
                             content_offset, block_text, state, state_machine):
    # support giving explicit tabulary column definition to latex
    node = addnodes.tabular_col_spec()
    node['spec'] = arguments[0]
    return [node]
Example #34
0
 def run(self):
     node = addnodes.tabular_col_spec()
     node['spec'] = self.arguments[0]
     return [node]