Skip to content Skip to sidebar Skip to footer

Generating Labels For Nodes Of A Custom Directive

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 .

Solution 1:

I had the same problem as you and was able to resolve the issue by looking at the autosectionlabel extension.

What they do there is to add the reference to the labels domain data. I got it working inside a custom directive like so:

nodeId = nodes.make_id("some-id")
self.env.app.env.domaindata["std"]["labels"][nodeId] = self.env.docname, nodeId, "Title"
section = nodes.section(ids=[nodeId])
section.append(nodes.title(text="Title"))

Key is the second line of the code above.

Also you want to add the label to the anonlabels to be able to reference it via

:ref:`foo <nodeId>`

like so:

self.env.app.env.domaindata["std"]["anonlabels"][nodeId] = self.env.docname, nodeId

Solution 2:

I found one way to perform this operation. It likely only works for HTML output:

`Text related to todo-0 <introduction.html#todo-0>`_

This reference link will successfully link to the TODO. All other reference attempts fail. i.e. These all fail:

Note: these syntaxes donot work::

    `introduction.html#todo-1`_

    :ref:`introduction.html#todo-1`:ref:`todo-1`

Post a Comment for "Generating Labels For Nodes Of A Custom Directive"