【发布时间】:2018-09-22 04:10:17
【问题描述】:
我正在用 sphinx 编写一个文档,其中包含三种主要类型的元素:标题、图像和纯文本。有时,有些元素需要居中:
Heading
=======
.. rst-class:: center
A centered paragraph, followed by non-centered image.
.. image:: /_static/exhibit_a.png
A non-centered paragraph, followed by centered image.
.. image:: /_static/exhibit_b.png
:class: center
常规文本和图像居中很好,因为我注册了一个如下所示的 CSS 文件:
.center { text-align: center; }
img.center {
display: block;
margin: auto;
}
但是,以下内容无法按预期工作:
.. rst-class: center
===================
A Heading 1 Element
===================
Some generic text
reST class (sphinx rst-class) 指令应该只应用于紧随其后的元素,但在这种情况下,整个部分将居中对齐,其中包含所有内容。在此示例中,Some generic text 居中,但应左对齐。实际上,像这样将文档中的第一个标题居中几乎可以使整个文档居中。
如何将标题居中对齐,使其仅适用于 <h1> 标记而不是整个部分?
我在 sphinx 1.8.0 上使用 Read the Docs 主题,以防万一。
其他想法
就我而言,我需要修改所有 <h1> 和 <h2> 实例,并且不需要修改其他标题。我知道这在 CSS 中是微不足道的
h1 h2 { text-align: center; }
但是,这个特定的文档是一个更大的项目的一部分,我希望在这个项目中保持所有原始样式不变。做到这一点的唯一方法是只为这个文档包含我的 CSS 自定义。这是一个可能的替代方案吗?
更多想法
发生错误是因为center 类被附加到围绕整个部分的<div>,而不是<h1> 标记。但是,我希望能够允许某些 div(如延长线)具有 center 类。只是不是带有 section 类的 div。
【问题讨论】:
标签: python python-sphinx restructuredtext