restructuredText说明文档

作者:xulihang
时间:2018年04月24日

指令(Directives)

Directives是Roles之外的另一个rst使用的显式标记,用以拓展它的功能。Directive block包含三个部分:参数(arguments),选项(options,一个rst语法表示的列表),内容(content)。

它的结构通常是这样的::

+-------+-------------------------------+
| ".. " | directive type "::" directive |
+-------+ block                         |
        |                               |
        +-------------------------------+

比如插入一个图片::

.. image:: http://www.w3school.com.cn//i/eg_tulip.jpg
http://www.w3school.com.cn//i/eg_tulip.jpg

插入一个危险提示::

.. DANGER::
    Beware killer rabbits!

Danger

Beware killer rabbits!

插入一个csv表格::

.. csv-table:: Frozen Delights!
   :header: "Treat", "Quantity", "Description"
   :widths: 15, 10, 30

   "Albatross", 2.99, "On a stick!"
   "Crunchy Frog", 1.49, "If we took the bones out, it wouldn't be crunchy, now would it?"
Frozen Delights!
Treat Quantity Description
Albatross 2.99 On a stick!
Crunchy Frog 1.49 If we took the bones out, it wouldn’t be crunchy, now would it?

角色(Roles)

被解释文本(Interpreted text)用 反引号(`)来标记。可以在它前面添加显式标记来改变效果。这就叫做角色(Roles)。

比如以下例子::

:emphasis:`text`

效果:text

我们还可以用directive自定义Role::

.. role:: raw-html(raw)
   :format: html

使用:
:raw-html:`a<br />b`

效果: a
b