添加指令的引用

时间:2016-03-07 11:18:47

标签: python python-sphinx

我正在尝试编写一个自定义指令,该指令发出对另一个部分的引用,但我找不到有关可用节点类型的任何文档或如何实用地发出引用。

test.rst

.. _test:

Test
====

.. test::

The test directive should generate a reference in the form of :ref:`test`.

test.py

from docutils import nodes
from docutils.parsers.rst import Directive

def setup(app):
    app.add_directive('test', TestDirective)
    return {'version': '0.1'}

class TestDirective(Directive):
    def run(self):
        # this would normally come from an argument on the directive
        name = 'test'

        node = nodes.block_quote()
        node += nodes.Text('The ref is: ')

        # this should emit :ref:`name` where name is variable
        # node += ???

        return [node]

1 个答案:

答案 0 :(得分:0)

你可以试试这个。

node += nodes.reference(refid=name)
相关问题