【问题标题】:Automatically create a toctree for autodoc classes in Sphinx自动为 Sphinx 中的 autodoc 类创建目录树
【发布时间】:2016-04-06 02:12:39
【问题描述】:

我希望增加我的一个库中的文档。我一直在使用 sphinx 来帮助构建文档,最近开始探索 autodoc 扩展。

似乎在大多数专业文档中,每个类文档页面都有一个所有文档方法的列表,顶部带有链接。或者,换句话说,顶部有一个目录树,其中包含指向每个更深入的方法文档的超链接。

有没有办法为使用 autodoc 记录的每个类自动创建此目录树?

【问题讨论】:

  • @mzjn,这很有趣,我已经部分实现了。但是,我仍然无法在存根内的类文档顶部获得目录树。
  • 哦,nvm 我很困惑。我让它工作了!如果您想发布答案,我会接受。否则我会为后代发布一个。

标签: python python-sphinx autodoc toctree


【解决方案1】:

在您的 conf.py 文件中添加 sphinx

extensions = ['sphinx.ext.autosummary',]
# NOTE: Don't overwrite your old extension list! Just add to it!

autodoc_default_flags = ['members']
autosummary_generate = True

我将目录树放在我的 index.rst 中,它看起来像这样:

.. autosummary::
     :toctree: stubs

     Class1
     Class2
     Class3

请参阅this example 了解 conf.py 设置

this example 是目录树的示例。

希望有帮助!

【讨论】:

    猜你喜欢
    • 2011-02-11
    • 2015-02-04
    • 2021-05-07
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-24
    • 1970-01-01
    相关资源
    最近更新 更多