コード例 #1
0
ファイル: nodes.py プロジェクト: dvasiliauskas/sphinx
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc,
                        traversed):
    # type: (Builder, Set[unicode], unicode, nodes.Node, Callable, nodes.Node) -> nodes.Node
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(text_type, toctreenode['includefiles'])
        for includefile in includefiles:
            if includefile not in traversed:
                try:
                    traversed.append(includefile)
                    logger.info(colorfunc(includefile) + " ", nonl=1)
                    subtree = inline_all_toctrees(
                        builder, docnameset, includefile,
                        builder.env.get_doctree(includefile), colorfunc,
                        traversed)
                    docnameset.add(includefile)
                except Exception:
                    logger.warning(
                        'toctree contains ref to nonexisting file %r',
                        includefile,
                        location=docname)
                else:
                    sof = addnodes.start_of_file(docname=includefile)
                    sof.children = subtree.children
                    for sectionnode in sof.traverse(nodes.section):
                        if 'docname' not in sectionnode:
                            sectionnode['docname'] = includefile
                    newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #2
0
ファイル: nodes.py プロジェクト: vh999/sphinx
def inline_all_toctrees(builder: "Builder", docnameset: Set[str], docname: str,
                        tree: nodes.document, colorfunc: Callable,
                        traversed: List[str]) -> nodes.document:
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = cast(nodes.document, tree.deepcopy())
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(str, toctreenode['includefiles'])
        for includefile in includefiles:
            if includefile not in traversed:
                try:
                    traversed.append(includefile)
                    logger.info(colorfunc(includefile) + " ", nonl=True)
                    subtree = inline_all_toctrees(
                        builder, docnameset, includefile,
                        builder.env.get_doctree(includefile), colorfunc,
                        traversed)
                    docnameset.add(includefile)
                except Exception:
                    logger.warning(
                        __('toctree contains ref to nonexisting file %r'),
                        includefile,
                        location=docname)
                else:
                    sof = addnodes.start_of_file(docname=includefile)
                    sof.children = subtree.children
                    for sectionnode in sof.traverse(nodes.section):
                        if 'docname' not in sectionnode:
                            sectionnode['docname'] = includefile
                    newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #3
0
ファイル: nodes.py プロジェクト: czelsa/porownywarka-ofert
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc):
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(str, toctreenode['includefiles'])
        for includefile in includefiles:
            try:
                builder.info(colorfunc(includefile) + " ", nonl=1)
                subtree = inline_all_toctrees(
                    builder, docnameset, includefile,
                    builder.env.get_doctree(includefile), colorfunc)
                docnameset.add(includefile)
            except Exception:
                builder.warn(
                    'toctree contains ref to nonexisting '
                    'file %r' % includefile, builder.env.doc2path(docname))
            else:
                sof = addnodes.start_of_file(docname=includefile)
                sof.children = subtree.children
                newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #4
0
ファイル: nodes.py プロジェクト: sam-m888/sphinx
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc, traversed):
    # type: (Builder, Set[unicode], unicode, nodes.Node, Callable, nodes.Node) -> nodes.Node
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(text_type, toctreenode['includefiles'])
        for includefile in includefiles:
            if includefile not in traversed:
                try:
                    traversed.append(includefile)
                    logger.info(colorfunc(includefile) + " ", nonl=1)
                    subtree = inline_all_toctrees(builder, docnameset, includefile,
                                                  builder.env.get_doctree(includefile),
                                                  colorfunc, traversed)
                    docnameset.add(includefile)
                except Exception:
                    logger.warning(__('toctree contains ref to nonexisting file %r'),
                                   includefile, location=docname)
                else:
                    sof = addnodes.start_of_file(docname=includefile)
                    sof.children = subtree.children
                    for sectionnode in sof.traverse(nodes.section):
                        if 'docname' not in sectionnode:
                            sectionnode['docname'] = includefile
                    newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #5
0
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc, include_maintoc=False):
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        #if include_maintoc:
        #    newnodes.append(shape_latex_nodes.sectiontoc())
        #else:
        include_maintoc = True
        includefiles = map(text_type, toctreenode['includefiles'])
        for includefile in includefiles:
            try:
                builder.info(colorfunc(includefile) + " ", nonl=1)
                subtree = inline_all_toctrees(builder, docnameset, includefile,
                                              builder.env.get_doctree(includefile),
                                              colorfunc, include_maintoc=True)
                docnameset.add(includefile)
            except Exception:
                builder.warn('toctree contains ref to nonexisting '
                             'file %r' % includefile,
                             builder.env.doc2path(docname))
            else:
                sof = addnodes.start_of_file(docname=includefile)
                sof.children = subtree.children
                for sectionnode in sof.traverse(nodes.section):
                    if 'docname' not in sectionnode:
                        sectionnode['docname'] = includefile
                newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #6
0
ファイル: nodes.py プロジェクト: SvenDowideit/clearlinux
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc):
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(unicode, toctreenode['includefiles'])
        for includefile in includefiles:
            try:
                builder.info(colorfunc(includefile) + " ", nonl=1)
                subtree = inline_all_toctrees(builder, docnameset, includefile,
                    builder.env.get_doctree(includefile), colorfunc)
                docnameset.add(includefile)
            except Exception:
                builder.warn('toctree contains ref to nonexisting '
                             'file %r' % includefile,
                             builder.env.doc2path(docname))
            else:
                sof = addnodes.start_of_file(docname=includefile)
                sof.children = subtree.children
                newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #7
0
ファイル: slatex.py プロジェクト: shpsec-blaisep/template
 def assemble_doctree(self, indexfile, toctree_only, appendices):
     tree = self.env.get_doctree(indexfile)
     largetree = super(sLaTeXBuilder, self).assemble_doctree(indexfile, toctree_only, appendices)
     if not tree.traverse(addnodes.toctree):
         # we need to wrap the doctree inside a `start_of_file` node which
         # needs to be visited before `document` to set `curfilestack` on
         # the `LaTeXTranslator` class.
         docname = largetree['docname']
         sof = addnodes.start_of_file(docname=docname)
         sof.reporter = largetree.reporter
         del largetree.reporter
         sof.children = [largetree]
         largetree = sof
     return largetree
コード例 #8
0
ファイル: slatex.py プロジェクト: shpsec-blaisep/template
 def assemble_doctree(self, indexfile, toctree_only, appendices):
     tree = self.env.get_doctree(indexfile)
     largetree = super(sLaTeXBuilder,
                       self).assemble_doctree(indexfile, toctree_only,
                                              appendices)
     if not tree.traverse(addnodes.toctree):
         # we need to wrap the doctree inside a `start_of_file` node which
         # needs to be visited before `document` to set `curfilestack` on
         # the `LaTeXTranslator` class.
         docname = largetree['docname']
         sof = addnodes.start_of_file(docname=docname)
         sof.reporter = largetree.reporter
         del largetree.reporter
         sof.children = [largetree]
         largetree = sof
     return largetree
コード例 #9
0
    def apply(self, **kwargs: Any) -> None:
        def checkNodeIsInPart(part, node):
            if "chapters" in part:
                nodefile = node.children[0].attributes["docname"]
                chapfiles = part["chapters"]
                for chap in chapfiles:
                    if nodefile in chap.values():
                        return True
            return False

        docname = self.document["source"]
        if get_filename(docname) == self.app.config.master_doc:
            TOC_PATH = Path(self.app.confdir).joinpath("_toc.yml")
            tocfile = yaml.safe_load(TOC_PATH.read_text("utf8"))

            # store bibliography nodes to append it at the end of doc
            bibNodes = []
            for bibnode in self.document.traverse(thebibliography):
                bibNodes.append(bibnode)
                replaceWithNode(bibnode, HiddenCellNode, False)

            for f in tocfile:
                if "part" in f:
                    self.app.config["latex_toplevel_sectioning"] = "part"
                    partname = f["part"]
                    compoundParent = docutils.nodes.compound("")
                    compoundParent["classes"] = "toctree-wrapper"
                    startOfFile = addnodes.start_of_file("")
                    startOfFile["docname"] = partname
                    title = docutils.nodes.title(text=partname)
                    sectionName = docutils.nodes.section("")
                    sectionName["docname"] = partname
                    startOfFile.append(sectionName)
                    sectionName.append(title)
                    compoundParent.append(startOfFile)
                    for node in self.document.traverse(docutils.nodes.compound):
                        flag = checkNodeIsInPart(f, node)
                        if flag:
                            nodecopy = node
                            replaceWithNode(node, HiddenCellNode, False)
                            sectionName.append(nodecopy)
                    self.document.append(compoundParent)
            # append bib at the end
            if len(bibNodes):
                self.document.extend(bibNodes)
コード例 #10
0
    def process_tree_structure(self, ordered, docname, traversed, depth=0):
        omit = False
        max_depth = self.config.confluence_max_doc_depth
        if max_depth is not None and depth > max_depth:
            omit = True
            self.omitted_docnames.append(docname)

        if not omit:
            ordered.append(docname)

        modified = False
        doctree = self.env.get_doctree(docname)
        for toctreenode in doctree.traverse(addnodes.toctree):
            if not omit and max_depth is not None:
                if (toctreenode['maxdepth'] == -1 or
                        depth + toctreenode['maxdepth'] > max_depth):
                    new_depth = max_depth - depth
                    assert new_depth >= 0
                    toctreenode['maxdepth'] = new_depth
            movednodes = []
            for child in toctreenode['includefiles']:
                if child not in traversed:
                    ConfluenceState.registerParentDocname(child, docname)
                    traversed.append(child)

                    children = self.process_tree_structure(
                        ordered, child, traversed, depth+1)
                    if children:
                        movednodes.append(children)
                        self._fix_std_labels(child, docname)

            if movednodes:
                modified = True
                toctreenode.replace_self(movednodes)
                toctreenode.parent['classes'].remove('toctree-wrapper')

        if omit:
            container = addnodes.start_of_file(docname=docname)
            container.children = doctree.children
            return container
        elif modified:
            self.env.resolve_references(doctree, docname, self)
コード例 #11
0
ファイル: builder.py プロジェクト: mwmattis/confluencebuilder
    def process_tree_structure(self, ordered, docname, traversed, depth=0):
        omit = False
        max_depth = self.config.confluence_max_doc_depth
        if max_depth is not None and depth > max_depth:
            omit = True
            self.omitted_docnames.append(docname)

        if not omit:
            ordered.append(docname)

        modified = False
        doctree = self.env.get_doctree(docname)
        for toctreenode in doctree.traverse(addnodes.toctree):
            if not omit and max_depth is not None:
                if (toctreenode['maxdepth'] == -1
                        or depth + toctreenode['maxdepth'] > max_depth):
                    new_depth = max_depth - depth
                    assert new_depth >= 0
                    toctreenode['maxdepth'] = new_depth
            movednodes = []
            for child in toctreenode['includefiles']:
                if child not in traversed:
                    ConfluenceState.registerParentDocname(child, docname)
                    traversed.append(child)

                    children = self.process_tree_structure(
                        ordered, child, traversed, depth + 1)
                    if children:
                        movednodes.append(children)
                        self._fix_std_labels(child, docname)

            if movednodes:
                modified = True
                toctreenode.replace_self(movednodes)
                toctreenode.parent['classes'].remove('toctree-wrapper')

        if omit:
            container = addnodes.start_of_file(docname=docname)
            container.children = doctree.children
            return container
        elif modified:
            self.env.resolve_references(doctree, docname, self)
コード例 #12
0
def inline_all_toctrees(builder,
                        docnameset,
                        docname,
                        tree,
                        colorfunc,
                        include_maintoc=False):
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        #if include_maintoc:
        #    newnodes.append(shape_latex_nodes.sectiontoc())
        #else:
        include_maintoc = True
        includefiles = map(text_type, toctreenode['includefiles'])
        for includefile in includefiles:
            try:
                builder.info(colorfunc(includefile) + " ", nonl=1)
                subtree = inline_all_toctrees(
                    builder,
                    docnameset,
                    includefile,
                    builder.env.get_doctree(includefile),
                    colorfunc,
                    include_maintoc=True)
                docnameset.add(includefile)
            except Exception:
                builder.warn(
                    'toctree contains ref to nonexisting '
                    'file %r' % includefile, builder.env.doc2path(docname))
            else:
                sof = addnodes.start_of_file(docname=includefile)
                sof.children = subtree.children
                for sectionnode in sof.traverse(nodes.section):
                    if 'docname' not in sectionnode:
                        sectionnode['docname'] = includefile
                newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #13
0
 def process_tree(docname, tree):
     tree = tree.deepcopy()
     for toctreenode in tree.traverse(addnodes.toctree):
         newnodes = []
         includefiles = map(str, toctreenode['includefiles'])
         for includefile in includefiles:
             try:
                 self.spinx_logger.info(darkgreen(includefile) + " ")
                 subtree = process_tree(includefile,
                 self.env.get_doctree(includefile))
                 self.docnames.add(includefile)
             except Exception:
                 self.warn('%s: toctree contains ref to nonexisting file %r'\
                                              % (docname, includefile))
             else:
                 sof = addnodes.start_of_file(docname=includefile)
                 sof.children = subtree.children
                 newnodes.append(sof)
         toctreenode.parent.replace(toctreenode, newnodes)
     return tree
コード例 #14
0
ファイル: pdfbuilder.py プロジェクト: ajford/rst2pdf
 def process_tree(docname, tree):
     tree = tree.deepcopy()
     for toctreenode in tree.traverse(addnodes.toctree):
         newnodes = []
         includefiles = map(str, toctreenode['includefiles'])
         for includefile in includefiles:
             try:
                 self.info(darkgreen(includefile) + " ", nonl=1)
                 subtree = process_tree(includefile,
                 self.env.get_doctree(includefile))
                 self.docnames.add(includefile)
             except Exception:
                 self.warn('%s: toctree contains ref to nonexisting file %r'\
                                              % (docname, includefile))
             else:
                 sof = addnodes.start_of_file(docname=includefile)
                 sof.children = subtree.children
                 newnodes.append(sof)
         toctreenode.parent.replace(toctreenode, newnodes)
     return tree
コード例 #15
0
def insert_all_toctrees(tree, env, traversed):
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        nodeid = 'docx_expanded_toctree%d' % id(toctreenode)
        newnodes = nodes.container(ids=[nodeid])
        toctreenode['docx_expanded_toctree_refid'] = nodeid
        includefiles = toctreenode['includefiles']
        for includefile in includefiles:
            if includefile in traversed:
                continue
            try:
                traversed.append(includefile)
                subtree = insert_all_toctrees(env.get_doctree(includefile),
                                              env, traversed)
            except Exception:
                continue
            start_of_file = addnodes.start_of_file(docname=includefile)
            start_of_file.children = subtree.children
            newnodes.append(start_of_file)
        parent = toctreenode.parent
        index = parent.index(toctreenode)
        parent.insert(index + 1, newnodes)
    return tree
コード例 #16
0
ファイル: xlatex.py プロジェクト: xcore/xdoc
def inline_all_toctrees(builder, docnameset, docname, tree, colorfunc, toplevel =True):
    """Inline all toctrees in the *tree*.

    Record all docnames in *docnameset*, and output docnames with *colorfunc*.
    """
    tree = tree.deepcopy()
    for toctreenode in tree.traverse(addnodes.toctree):
        newnodes = []
        includefiles = map(str, toctreenode['includefiles'])
        for includefile in includefiles:
            try:
                builder.info(colorfunc(includefile) + " ", nonl=1)
                subtree = inline_all_toctrees(builder, docnameset, includefile,
                    builder.env.get_doctree(includefile), colorfunc,toplevel=False)
                docnameset.add(includefile)
            except Exception:
                builder.warn('toctree contains ref to nonexisting '
                             'file %r' % includefile,
                             builder.env.doc2path(docname))
            else:
                sof = addnodes.start_of_file(docname=includefile)
                sof.children = subtree.children
                if toplevel:
                    for node in sof.traverse(nodes.title):
                        alt_title = None
                        for (title, docname) in toctreenode['entries']:
                            if docname == includefile:
                                alt_title = title

                        if alt_title:
                            node.children = [nodes.Text(alt_title)]
                        break

                newnodes.append(sof)
        toctreenode.parent.replace(toctreenode, newnodes)
    return tree
コード例 #17
0
def _inline_all_toctrees(builder, docnameset, docname, tree, colorfunc,
                         traversed, replace):
    tree = cast(nodes.document, tree.deepcopy())
    for toctreenode in list(tree.traverse(addnodes.toctree)):
        newnodes = []
        includefiles = map(str, toctreenode['includefiles'])
        for includefile in includefiles:
            if includefile not in traversed:
                try:
                    traversed.append(includefile)
                    logger.info(colorfunc(includefile) + " ", nonl=True)
                    subtree = _inline_all_toctrees(
                        builder, docnameset, includefile,
                        builder.env.get_doctree(includefile), colorfunc,
                        traversed, replace)
                    docnameset.add(includefile)
                except Exception:
                    logger.warn(
                        __('toctree contains ref to nonexisting file %r'),
                        includefile,
                        location=docname)
                else:
                    sof = addnodes.start_of_file(docname=includefile)
                    sof.children = subtree.children
                    for sectionnode in sof.traverse(nodes.section):
                        if 'docname' not in sectionnode:
                            sectionnode['docname'] = includefile
                    newnodes.append(sof)

        if replace:
            toctreenode.parent.replace(toctreenode, newnodes)
        else:
            for node in newnodes:
                toctreenode.parent.append(node)

    return tree