【问题标题】:Reference a custom figure type in Sphinx在 Sphinx 中引用自定义图形类型
【发布时间】:2020-01-24 23:57:05
【问题描述】:

如果我尝试引用自定义图形类

class MyFigure(
    sphinx.util.docutils.SphinxDirective, 
    docutils.parsers.rst.directives.images.Figure
):
    pass

def setup(app):
    app.add_role('fig', MyFigure)

然后像这样使用它

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


Look at :ref:`myfig`.

任何引用都将失败

WARNING: undefined label: myfig

如何解决这个问题?

【问题讨论】:

    标签: python-sphinx restructuredtext docutils


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-07-28
      • 1970-01-01
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多