jterrace / sphinxtr

The Sphinx Thesis Resource
http://jterrace.github.com/sphinxtr
Other
153 stars 50 forks source link

numsec: Keep node structure #31

Closed Jellby closed 9 years ago

Jellby commented 9 years ago

Is this still maintained?

I realized that numsec is relying on a particular structure of the reference nodes: it assumes there is an emphasis node (or some other kind of node) inside, and it removes it. I don't think it should alter the structure. If one wants to remove the emphasis node, it should be done somewhere else, not in this extension.

So I propose this code for the inner loop in doctree_resolved, to replace only the text nodes:

        if refdocname in secnums:
            secnum = secnums[refdocname]
            for child in node.traverse():
                if isinstance(child, nodes.Text):
                    text = child.astext()
                    toclist = app.builder.env.tocs[refdocname]
                    anchorname = None
                    for refnode in toclist.traverse(nodes.reference):
                        if refnode.astext() == text:
                            anchorname = refnode['anchorname']
                    if anchorname is None:
                        continue
                    linktext = '.'.join(map(str, secnum[anchorname]))
                    child.parent.replace(child, nodes.Text(linktext))
jterrace commented 9 years ago

Yes, I maintain the repository.

Send me a pull request?