How to make toctree link refer to the separate file like it refers to the subsections

纵然是瞬间 提交于 2021-02-15 16:31:10

问题


Structure

The following structure of the project:

  • index.rst

    MyProject
    =========
    
    Contents:
    
    .. toctree::
    
       group1
    
  • group1.rst

    Group1
    ------
    
    Subgroup1
    =========
    
    Subgroup1 contents
    
    Subgroup2
    =========
    
    Subgroup2 contents
    

Rendered to (after clicking on Group1 -> Subgroup2):

As you can see it opens the Group1 page and linked to Subgroup2 section.

Want

I want to have the same on the left side (Group1 openned and Subgroup2 choosed) but on the right side I want to see only Subgroup2 page (page without Subgroup1 content).

I.e. have file group1/subgroup1.rst:

Subgroup2
=========

Subgroup2 contents

Rendered to:

How it can be achieved? This is a simple example with the depth 2, what about depth 3-4?


回答1:


You need to have a file per page of content. Sphinx doesn't break files into multiple pages.

What works for me is creating toctree directives that reference files containing sub-toctree directives. I like to create the sub-groups in directories, but you could do this within one directory.

index.rst:

MyProject
=========

Contents:

.. toctree::

   group1/index

group1/index.rst:

Group1
======

.. toctree::

   subgroup1
   subgroup2

group1/subgroup1.rst:

Subgroup1
=========

Subgroup1 contents

group1/subgroup2.rst:

Subgroup2
=========

Subgroup2 contents


来源:https://stackoverflow.com/questions/34249244/how-to-make-toctree-link-refer-to-the-separate-file-like-it-refers-to-the-subsec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!