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))
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: