简体   繁体   English

Python-Sphinx 中 Toctree 的多个级别

[英]Multiple Levels of Toctree's in Python-Sphinx

I'm trying to use sphinx in a way to document multiple "levels" of documentation, eg:我正在尝试使用 sphinx 来记录多个“级别”的文档,例如:

  • Api Reference接口参考
  • Manual手动的
  • Tutorials教程
  • Etc.等等。

The idea is that the Table of Contents is shown on the sidebar relative to the section you're in. So when you're on the main index it only shows the sections mentioned above.这个想法是目录相对于您所在的部分显示在侧边栏上。所以当您在主索引上时,它只显示上面提到的部分。 When you go into eg.当你进入例如。 "Manual" it shows a different ToC specific to that section, and a way to go back to the main ToC. “手册”显示了特定于该部分的不同 ToC,以及返回主 ToC 的方法。

I've been trying to figure out how to get this to work in Sphinx without hacking it in, but so far can't quite figure out a way.我一直在试图弄清楚如何让它在 Sphinx 中工作而不入侵它,但到目前为止还想不出办法。 The folder structure is already reflecting the different sections (ie. all "manual" documentation is stored under _source/manual) and I've tried placing separate index files in each of those directories, but it appears that the toctree functionality only looks at the main index file.文件夹结构已经反映了不同的部分(即所有“手册”文档都存储在 _source/manual 下),我已经尝试在每个目录中放置单独的索引文件,但似乎 toctree 功能只查看主索引文件。

I am using the "readthedocs" theme, the code I'm looking at specifically is https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html#L93我正在使用“readthedocs”主题,我正在查看的代码是https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html#L93

Can anyone tell me how I would go about adding a ToC like this using Sphinx?谁能告诉我如何使用 Sphinx 添加这样的 ToC?

Thank you谢谢

(Maybe a little bit late for this response) I have a similar situation, three sections contained in the same TOC Tree: (这个回复可能有点晚了)我有类似的情况,同一目录树中包含三个部分:

  • Hardware硬件
  • Software软件
  • Tutorials教程

I was trying to achieve the same, that is hiding from my sidebar menu everything that doesn't belong to the current toctree-l1.我试图实现相同的目标,即从我的侧边栏菜单中隐藏不属于当前 toctree-l1 的所有内容。 Knowing that Sphinx adds the CSS class 'current' I came up with:知道 Sphinx 添加了 CSS 类“current”,我想出了:

#sidebar li.toctree-l1:not(.current){
  display: none;
} 

It is not the best solution ever, but since Sphinx can only handle one main root for documentation and, from that one, it creates the entire TOC Tree, if you only need it for the sidebar menu, CSS should work for you.这不是有史以来最好的解决方案,但由于 Sphinx 只能处理文档的一个主根,并且从那个主根创建整个 TOC 树,如果您只需要侧边栏菜单,CSS 应该适合您。

Screenshot of my menu just showing content below one section:我的菜单的屏幕截图仅显示一个部分下方的内容:

It appears that a .. toctree:: in a document in a subdirectory is rooted at that subdirectory (see eg https://docs.python.org/2/_sources/howto/index.txt ) .似乎子目录中文档中的.. toctree::以该子目录为根(参见例如https://docs.python.org/2/_sources/howto/index.txt )。 For the upper-level TOC, :maxdepth: limits the inclusion of lower levels.对于上层 TOC, :maxdepth:限制包含较低层。

This can be placed into the sidebar by making a corresponding template and adding it to html_sidebars build parameter.这可以通过制作相应的模板并将其添加到html_sidebars构建参数来放置到侧边栏中。 UPDATE: doesn't work;更新:不起作用; in a sidebar template, TOC always has its root at the top.在侧边栏模板中,TOC 的根始终位于顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM