假设我的some.rst
文件如下所示:
============
My Title
============
1. Section
================
2. Section
=================
编译后,在生成some.html
的侧栏中会有一个目录,如下所示:
我的标题
- 部分
- 部分
有没有一种简单的方法可以从目录中删除“我的标题” some.html
?
假设我的some.rst
文件如下所示:
============
My Title
============
1. Section
================
2. Section
=================
编译后,在生成some.html
的侧栏中会有一个目录,如下所示:
我的标题
- 部分
- 部分
有没有一种简单的方法可以从目录中删除“我的标题” some.html
?
我能够通过使用上述.. raw:: html
方法解决这个问题,稍作调整(避免破坏自动生成的 TOC)。如前所述,如果您的文件仅包含.. raw:: html
标题,它将破坏 Sphinx 自动生成的目录。但是,如果您在其下方使用.. raw:: html
并添加---------------------
,它将不会显示在左侧导航中,也不会破坏 TOC。例如
所以我终于不小心想出了如何让标题不在左侧目录中显示。如果您的文件仅包含.. raw:: html
h2 标题,它将破坏 sphinx 自动生成的目录(如 stackoverflow 文章中所述)。但是,如果您在它下方使用它.. raw:: html
,---------------------
它将不会显示在左侧导航中,也不会破坏 TOC :star2: eg
.. raw:: html
<h2>What Can I Do With KSQL?</h2>
---------------------
简单的方法是使用被 TOC 指令忽略的对象类型:
.. rubric:: My Title
这会创建看起来有点像标题的文本,但会从 TOC 中排除。你可以用你想要的任何样式来更新你的 CSS 文件,.rubric
如果你喜欢,甚至可以模仿 h1 样式。
请参阅“ Restructuredtext 页面中的非 TOC 标题”了解如何定义 rubric 样式类。
这个聚会很晚了,我知道。我刚遇到这个问题,需要模仿 h2 并且无法编辑样式表。
我的解决方案最终是在以下位置添加原始 html some.rst
:
:raw-html:`<h1>My Title</h1>`
1. Section
================
2. Section
=================
您可以制作自己的 h3 标签。
对于您的标题,您使用:
|start-h3| My title |end-h3|
稍后在您编写的文件末尾:
.. |start-h3| raw:: html
<h3>
.. |end-h3| raw:: html
</h3>
您似乎在谈论本地目录(“在此页面上”目录)。不幸的是,Sphinx 总是将文档标题打印为第一项 ( <li>
)。实际的本地 TOC(章节标题)都嵌套<ul>
在第一个文档标题<li>
中。(是的,这很烦人。)
你有两个选择:
如果当前 Sphinx 主题具有本地目录,则必须调整生成的 HTML 标记。例如,通过使用 CSS 隐藏文档标题。从https://techwriter.documatt.com/2021/sphinx-localtoc-remove-document-title.html复制粘贴:
.localtoc > ul {
margin: 0;
}
.localtoc > ul > li {
list-style-type: none;
}
.localtoc > ul > li > a {
display: none;
}
.localtoc > ul > li > ul {
// any additional styles to local toc <ul>
}
替代方法可能是手动打印本地 TOCcontents::
,例如在带有指令及其:local:
选项的文档的开头。取自https://restructuredtext.documatt.com/element/contents.html#no-current-document-title的示例:
#################################
Contents without a document title
#################################
Testing ``contents::`` directive with ``:local:`` flag.
.. contents::
:local:
**********
Section L2
**********
Section L3
==========