I have an extension that was working correctly in Sphinx 1.2.1.  But I just 
upgraded to 1.3.1, and it no longer works.

The extension is used for automatically numbering elements in documents 
(figures, tables, examples, etc.).  It defines two new roles: "autonumber" 
for elements to be numbered, and "numref" for references to them.  
"autonumber" elements are still getting processed correctly, but all the 
"numref" ones are now being ignored.  In particular, I loop over them with 
"for ref_info in doctree.traverse(autonumber_ref)", and that no longer 
finds anything to loop over.  Does anyone have an idea what I need to 
change to make it work under 1.3.1?

Thanks!  Here's the full code for the extension.


from docutils.parsers.rst import roles
> from docutils.nodes import Text, reference, section
> from sphinx.roles import XRefRole
>     
> class autonumber(Text):
>     pass
>     
> class autonumber_ref(reference):
>     pass
>
> def autonumber_role(name, rawtext, text, lineno, inliner, options={}, 
> content=[]):
>     return ([autonumber(text)], [])
>
> def doctree_resolved(app, doctree, docname):
>     index = {};
>     refTable = {}
>     if app.config.autonumber_by_chapter:
>         # Record the number of each chapter
>         
>         env = app.builder.env
>         sectionNumbers = {}
>         for doc in env.toc_secnumbers:
>             sections = env.toc_secnumbers[doc]
>             for sectionId in sections:
>                 sectionNumbers[sectionId[1:]] = sections[sectionId]
>         lastChapter = -1
>     
>     # Assign numbers to all the autonumbered objects.
>     
>     for node in doctree.traverse(autonumber):
>         category = node.astext().split(',')[0]
>         if category in index:
>             nextNumber = index[category]+1
>         else:
>             nextNumber = 1
>         if app.config.autonumber_by_chapter:
>             parent = node.parent
>             chapter = None
>             while chapter is None:
>                 if isinstance(parent, section):
>                     chapter = parent
>                 parent = parent.parent
>             chapter = sectionNumbers[chapter.attributes['ids'][0]][0]
>             if chapter != lastChapter:
>                 index = {}
>                 nextNumber = 1
>             newNode = Text('%s %d-%d' % (category, chapter, nextNumber))
>             lastChapter = chapter
>         else:
>             newNode = Text('%s %d' % (category, nextNumber))            
>         index[category] = nextNumber
>         refTable[node.astext()] = newNode
>         node.parent.replace(node, newNode)
>     
>     # Replace references with the name of the referenced object
>     
>     for ref_info in doctree.traverse(autonumber_ref):
>         target = ref_info['reftarget']
>         if target not in refTable:
>             raise ValueError('Unknown target for autonumber reference: 
> '+target)
>         ref_info.replace_self(Text(refTable[target].astext()))
>
> def setup(app):
>     app.add_config_value('autonumber_by_chapter', True, False)
>     roles.register_local_role('autonumber', autonumber_role)
>     app.add_node(autonumber)
>     app.add_node(autonumber_ref)
>     app.add_role('numref', XRefRole(nodeclass=autonumber_ref))
>     app.connect('doctree-resolved', doctree_resolved)
>

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sphinx-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to