pdfbuilder.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:deviation-manual 作者: DeviationTX 项目源码 文件源码
def build_contents(self, node, level=0):
        level += 1
        sections=[]
        # Replaced this with the for below to make it work for Sphinx
        # trees.

        #sections = [sect for sect in node if isinstance(sect, nodes.section)]
        for sect in node:
            if isinstance(sect,nodes.compound):
                for sect2 in sect:
                    if isinstance(sect2,addnodes.start_of_file):
                        for sect3 in sect2:
                            if isinstance(sect3,nodes.section):
                                sections.append(sect3)
            elif isinstance(sect, nodes.section):
                sections.append(sect)
        entries = []
        autonum = 0
        # FIXME: depth should be taken from :maxdepth: (Issue 320)
        depth = self.toc_depth
        for section in sections:
            title = section[0]
            auto = title.get('auto')    # May be set by SectNum.
            entrytext = self.copy_and_filter(title)
            reference = nodes.reference('', '', refid=section['ids'][0],
                                        *entrytext)
            ref_id = self.document.set_id(reference)
            entry = nodes.paragraph('', '', reference)
            item = nodes.list_item('', entry)
            if ( self.backlinks in ('entry', 'top')
                 and title.next_node(nodes.reference) is None):
                if self.backlinks == 'entry':
                    title['refid'] = ref_id
                elif self.backlinks == 'top':
                    title['refid'] = self.toc_id
            if level < depth:
                subsects = self.build_contents(section, level)
                item += subsects
            entries.append(item)
        if entries:
            contents = nodes.bullet_list('', *entries)
            if auto:
                contents['classes'].append('auto-toc')
            return contents
        else:
            return []
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号