Python sphinx 在Sphinx中引用自定义地物类型

Python sphinx 在Sphinx中引用自定义地物类型,python-sphinx,restructuredtext,docutils,Python Sphinx,Restructuredtext,Docutils,如果我尝试引用自定义地物类 类MyFigure( sphinx.util.docutils.SphinxDirective, docutils.parsers.rst.directions.images.Figure ): 通过 def设置(应用程序): app.add_角色('fig',MyFigure) 然后像这样使用它 .. fig:: foo.png :name: myfig Look at :ref:`myfig`. 任何引用都将失败 WARNING: undefine

如果我尝试引用自定义地物类

类MyFigure(
sphinx.util.docutils.SphinxDirective,
docutils.parsers.rst.directions.images.Figure
):
通过
def设置(应用程序):
app.add_角色('fig',MyFigure)
然后像这样使用它

.. fig:: foo.png
    :name: myfig


Look at :ref:`myfig`.
任何引用都将失败

WARNING: undefined label: myfig

如何修复此问题?

docutils.parsers.rst.directives.images.Figure不是要自定义的正确类,因为它不处理
name
属性。改用Sphinx的补丁版本,
Sphinx.directives.patches.Figure