Non-TOC headings within a Restructuredtext page

僤鯓⒐⒋嵵緔 提交于 2019-12-05 10:34:49

You can create custom styles for rubrics that mimic your heading styles.

(1) In your ReST source, define custom styles like this:

.. role:: style1
    :class: class1

.. role:: style2
    :class: class2

Here "style_" is the handle to refer to these in ReST, and "class_" is the CSS class name.

(2) Use the above as inline styles in rubrics:

.. rubric:: :style1:`fake H1`

.. rubric:: :style2:`fake H2`

(3) In whatever CSS file makes sense, define styles for the new classes:

.rubric > .class1 {
    whatever
}

.rubric > .class2 {
    whatever
}

Here the "whatever" could be identical to existing styles for H1, H2 etc. if you wish.

Note: in step (3), you could define the CSS selectors more broadly or narrowly. If the new class names are globally unique, the selector could be as simple as .class1; or if you want to use the style just for top-level rubrics like my example, you could use p.rubric > span.class1 instead.

Chris

Docutils, the reference implementation of reStructuredText, upon which Sphinx is built allows you to pass options to the table of contents directive which allow you to control how deep you want your table of contents to go into your document hierachy. From the reStructuredText documentation, the contents directive takes a depth option:

depth : integer

The number of section levels that are collected in the table of contents. The default is unlimited depth.

So to get your document structure with only your top level headings included in the table of contents, you could use

.. contents: Table of Contents
   :depth: 1

Edit: It seems that Sphinx implements its own table of contents directive, so you can use

.. toctree: Table of Contents
   :maxdepth: 1

instead of the first code block above. Also, take a look at the hidden option, this might be useful to control further the levels included in the table of contents.

For me, I had to add both :maxdepth:1 and :titlesonly: to the toctree section. This is added in the "parent" rst file (or whichever file contains the .. toctree::.

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