writer.py 文件源码

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

项目:pymotw3 作者: reingart 项目源码 文件源码
def visit_target(self, node):
        def add_target(id):
            # indexing uses standard LaTeX index markup, so the targets
            # will be generated differently
            if id.startswith('index-'):
                return
            # do not generate \phantomsection in \section{}
            anchor = not self.in_title
            self.body.append(self.hypertarget(id, anchor=anchor))

        # postpone the labels until after the sectioning command
        parindex = node.parent.index(node)
        try:
            try:
                next = node.parent[parindex+1]
            except IndexError:
                # last node in parent, look at next after parent
                # (for section of equal level) if it exists
                if node.parent.parent is not None:
                    next = node.parent.parent[
                        node.parent.parent.index(node.parent)]
                else:
                    raise
            if isinstance(next, nodes.section):
                if node.get('refid'):
                    self.next_section_ids.add(node['refid'])
                self.next_section_ids.update(node['ids'])
                return
            else:
                domain = self.builder.env.domains['std']
                figtype = domain.get_figtype(next)
                if figtype and domain.get_numfig_title(next):
                    ids = set()
                    # labels for figures go in the figure body, not before
                    if node.get('refid'):
                        ids.add(node['refid'])
                    ids.update(node['ids'])
                    self.push_hyperlink_ids(figtype, ids)
                    return
        except IndexError:
            pass
        if 'refuri' in node:
            return
        if node.get('refid'):
            add_target(node['refid'])
        for id in sorted(node['ids']):
            add_target(id)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号