Using the Sphinx "TODO" Directive example I would like to reference the todo
instances embedded within a .rst file. For example, if the .rst file content contains:
.. todo:: foo
.. todo:: bar
I can see that the following code (taken from the Sphinx TODO example page)
class TodoDirective(SphinxDirective):
# this enables content in the directive
has_content = True
def run(self):
targetid = 'todo-%d' % self.env.new_serialno('todo')
targetnode = nodes.target('', '', ids=[targetid])
todo_node = todo('\n'.join(self.content))
todo_node += nodes.title(_('Todo'), _('Todo'))
self.state.nested_parse(self.content, self.content_offset, todo_node)
if not hasattr(self.env, 'todo_all_todos'):
self.env.todo_all_todos = []
self.env.todo_all_todos.append({
'docname': self.env.docname,
'lineno': self.lineno,
'todo': todo_node.deepcopy(),
'target': targetnode,
})
return [targetnode, todo_node]
Creates target nodes with ids
: todo-0
and todo-1
.
That are successfully referenced by embedding the directive in a .rst file as:
.. todolist::
What I would like to do is reference the todo
items within a .rst file like this:
:ref:`todo-0`
:ref:`todo-1`
This would require getting the TodoDirective
to generate a label for each target node. I have not been able to figure out how to do so.
This simple project is posted here: https://github.com/natersoz/sphinx_sandbox