【问题标题】:Change Sphinx's template for table of contents更改 Sphinx 的目录模板
【发布时间】:2013-10-16 20:35:13
【问题描述】:

我正在使用 Sphinx 和我自己的模板来获得类似 twitter 引导文档的文档样式:http://getbootstrap.com/2.3.2/getting-started.html

在那里您可以看到左侧的导航,它是静态的,并且在您滚动时保持在同一位置。

因此有必要渲染我已经使用此功能实现的目录:

{{ toctree(maxdepth=1, collapse=False, includehidden=true) }}

这会输出以下内容:

<ul class="current">
    <li class="toctree-l1 current"><a class="current reference internal" href="">Introduction</a></li>
    <li class="toctree-l1"><a class="reference internal" href="#installation">Installation</a></li>
    <li class="toctree-l1"><a class="reference internal" href="#roadmap">Roadmap</a></li>
</ul>

但为了让它与引导程序一起工作,我需要以下输出:

<ul class="nav nav-list bs-docs-sidenav">
    <li><a href="#introduction"><i class="icon-chevron-right"></i> Introduction</a></li>
    <li><a href="#installation"><i class="icon-chevron-right"></i> Installation</a></li>
    <li><a href="#roadmap"><i class="icon-chevron-right"></i> Roadmap</a></li>
</ul>

所以我的问题是:我怎样才能做到这一点? toctree()函数有模板文件可以调整吗?

【问题讨论】:

    标签: html twitter-bootstrap templates python-sphinx toctree


    【解决方案1】:

    我遇到了类似的问题,我混合使用了自定义角色和 jQuery,根据我的角色位置调整了这个问题。 jQuery 将改变你需要的所有东西。

    【讨论】:

    • 什么是自定义角色?毕竟,我也是使用 jQuery 来操作 html 的。我认为这并不完美,也许 Sphinx 在这种情况下会更好,以便更好地自定义模板...
    • 自定义角色类似于:myrole:,您可以使用它来扩展标记。我认为这在这里没有帮助。据我所知,必须修改构建器。一旦我设法做到这一点,我会在这里写一个完整的答案。
    猜你喜欢
    • 2014-07-14
    • 1970-01-01
    • 2017-10-21
    • 2020-07-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多