【笔记】reStructuredText学习笔记

前言

reStructuredText(RST、ReST或reST)是一种用于文本数据的文件格式,主要用于 Python 编程语言社区的技术文档。(维基百科

注释

1
.. 单行注释
1
2
3
..
多行注释
多行注释

标题

  • 标题可以使用的符号有=-^"*
  • 标题环绕的符号长度必须大于等于标题文字字数
  • 一级标题必须上下环绕符号,其他级别的标题只需要下面环绕
  • 每当出现新的符号,就自动递减标题层级,出现的符号顺序不限
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
====
一级标题
====

二级标题
====

三级标题
----

四级标题
^^^^

五级标题
""""

六级标题
****
1
2
3
4
5
6
<h1 id="一级标题">一级标题</h1>
<h2 id="二级标题">二级标题</h2>
<h3 id="三级标题">三级标题</h3>
<h4 id="四级标题">四级标题</h4>
<h5 id="五级标题">五级标题</h5>
<h6 id="六级标题">六级标题</h6>

段落

  • 一个空格、多个空格、一个换行都会渲染为空格,只有多个换行才会渲染为换行
1
2
3
4
文本内容1
文本内容2 文本内容3

文本内容4 文本内容5
1
2
<p>文本内容1 文本内容2 文本内容3</p>
<p>文本内容4 文本内容5</p>

字体

斜体

1
*文本内容*
1
<em>文本内容</em>

粗体

1
**文本内容**
1
<strong>文本内容</strong>

上标

1
文\ :sup:`本`\ 内容
1
<sup></sup>内容

下标

1
文\ :sub:`本`\ 内容
1
<sub></sub>内容

分隔线

  • 分隔线由4个及以上-组成
1
----
1
<hr />

列表

无序列表

  • 无需列表可以使用的符号有:*-+
1
2
* 文本内容1
* 文本内容2
1
2
3
4
5
6
7
8
<ul>
<li>
文本内容1
<ul>
<li>文本内容2</li>
</ul>
</li>
</ul>
1
2
* 文本内容1
* 文本内容2
1
2
3
4
5
6
7
8
<ul>
<li>
文本内容1
<ul>
<li>文本内容2</li>
</ul>
</li>
</ul>

有序列表

  • 无需列表可以使用的符号有:1aAiI
1
2
1. 文本内容1
#. 文本内容2
1
2
3
4
<ol type="1">
<li>文本内容1</li>
<li>文本内容2</li>
</ol>

定义列表

1
2
文本内容1
文本内容2
  • 通过两个及以上空格分隔,也可以定义定义列表
1
文本内容1  文本内容2
1
2
3
4
5
6
<dl>
<dt>文本内容1</dt>
<dd>
<p>文本内容2</p>
</dd>
</dl>

链接

行内式链接

1
`文本内容 <https://example.com/>`_
1
<a href="https://example.com/">文本内容</a>

自动链接

1
https://example.com/ 
1
<a href="https://example.com/">https://example.com/</a>

锚点

1
2
3
4
5
====
锚点位置
====

`锚点位置`_
1
2
3
<h1 id="锚点位置">锚点位置</h1>

<a href="#锚点位置">文本内容</a>

图片

:alt::指定替换文本,缺省值为image
:width::指定图片宽度,单位为px
:height::指定图片高度,单位为px
:align::指定图片对齐方式

center:居中
left:居左
right:居右

1
2
3
4
5
.. image:: https://example.com/image.webp
:alt: 替换文本
:width: 200px
:height: 200px
:align: center
1
<img src="https://example.com/image.webp" class="align-center" width="200" height="200" alt="替换文本" />

图示

1
2
3
4
5
6
7
.. figure:: https://example.com/image.webp
:alt: 替换文本
:width: 200px
:height: 200px
:align: center

文本内容

代码

行内代码

1
``print()``
1
2
3
<p>
<code>print()</code>
</p>

代码块

1
2
3
::

print()
1
2
3
<pre>
<code>print()</code>
</pre>

高亮代码块

:emphasize-lines::定义高亮行号,多个行号用,分隔

1
2
3
4
5
.. code-block:: python
:linenos:
:emphasize-lines: 1

print()
1
2
3
4
5
6
7
8
9
10
11
<div class="sourceCode" id="cb1" data-linenos="">
<pre class="sourceCode python">
<code class="sourceCode python">
<span id="cb1-1">
<a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>
<span class="bu">print</span>
()
</span>
</code>
</pre>
</div>

引用

1
2
3
引用内容1

引用内容2
1
2
3
4
<blockquote>
<p>引用内容1</p>
<p>引用内容2</p>
</blockquote>

表格

1
2
3
4
5
6
== == ==
A B C
== == ==
A1 B1 C1
A2 B2 C2
== == ==
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
</tr>
</thead>
<tbody>
<tr>
<td>A1</td>
<td>B1</td>
<td>C1</td>
</tr>
<tr>
<td>A2</td>
<td>B2</td>
<td>C2</td>
</tr>
</tbody>
</table>

脚注

1
2
3
文本内容 [1]_

.. [1] 脚注内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<p>
文本内容
<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref">
<sup>1</sup>
</a>
</p>

<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr/>
<ol>
<li id="fn1">
<p>
脚注内容
<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a>
</p>
</li>
</ol>
</section>

文本替换

1
2
3
|被替换文本内容|

.. |被替换文本内容| replace:: 替换后文本内容
1
<p>替换后文本内容</p>

提示

1
2
3
.. note::

文本内容
1
2
3
4
5
6
<div class="note">
<div class="title">
<p>Note</p>
</div>
<p>文本内容</p>
</div>
1
2
3
.. warning::

文本内容
1
2
3
4
5
6
<div class="warning">
<div class="title">
<p>Warning</p>
</div>
<p>文本内容</p>
</div>
1
2
3
.. error::

文本内容
1
2
3
4
5
6
<div class="error">
<div class="title">
<p>Error</p>
</div>
<p>文本内容</p>
</div>
1
2
3
.. caution::

文本内容
1
2
3
4
5
6
<div class="caution">
<div class="title">
<p>Caution</p>
</div>
<p>文本内容</p>
</div>
1
2
3
.. tip::

文本内容
1
2
3
4
5
6
<div class="tip">
<div class="title">
<p>Tip</p>
</div>
<p>文本内容</p>
</div>

自定义样式文本块

1
.. className:: 文本内容
1
2
3
<div class="className">
<p>文本内容</p>
</div>

完成

参考文献

3vshej