RestStructedText 实例练习篇
Author: | Falcon Chen |
---|---|
Contact: | falcon_chen@qq.com |
Date: | $Date$ |
Copyright: | public |
Contents
Tip
一个非常好的 在线练习工具
列表
有序列表
-
- 一级项目1
-
- 缩进的二级项目1 1. 三级项目1(貌似无效) 2. 三级项目2 3. 三级项目3
- 缩进的二级项目2
-
一级项目2
-
一级项目3
无序列表
-
- 无序项目一级1
-
-
无序项目二级1
-
- 无序项目二级2
-
+无序项目3
-
-
无序项目一级2
特殊指令
指令类型: | “attention”,”caution”,”danger”,”error”,”hint”,”important”,”note”,”tip”,”warning”,”admonition” |
---|---|
example 1: |
!DANGER!
Don’t Do this!
example 2: | (缩进的部分会作为子部分加入段落) |
---|
Note
这是note指令
- 第一个段落的第二行,注意 缩进 和 空行
-
-
- 列表项目1
-
仍然是列表的内容,使用缩进
-
列表项目2
-
指令元素: | attention, caution, danger, error, hint, important, note, tip, warning,title |
---|---|
指令选项: | :class: , :name: |
指令内容: | 会当作主体(body)元素解析 |
figure
figure包含image的数据,包括 image options 和可选的标题(caption)
Note
figure与image有区别的,figure是包括了标题的,在解析为html时,figure的image元素会被div所包裹。如
.. figure:: picture.png :scale: 50 % :alt: map to buried treasure .. image:: picture.png :scale: 50 % :alt: map to buried treasure
html解析:
<div class="figure"> <img alt="map to buried treasure" src="picture.png" /> </div> <img alt="map to buried treasure" src="picture.png" />
Body元素
Line Block(行内块)
Parsed Literal Block(块原生解析)
这个不做实际解析了,用法如下:
.. parsed-literal:: ( (title_, subtitle_?)?, decoration_?, (docinfo_, transition_?)?, `%structure.model;`_ )
Code (Docutils 0.9新增,使用了 Pygments 做语法高亮)
用法如下:
.. code:: python def my_function(): "just a test" print 8/2
Epigraph
再见青春,再见美丽的疼痛。
——《汪峰-再见青春》
Compound
The ‘rm’ command is very dangerous. If you are logged in as root and enter
cd / rm -rf *
you will erase the entire contents of your file system.
Table
Caution!
请务必使用等宽字体进行表格的编写,不然你就会遇到跟我一样的各种莫名其妙的坑爹事!
推荐字体:Lucida Console ,文泉驿等宽微米黑(下载) 虽然也是等宽,但是在中文下也有视觉错误
test:
测试中文 |
---|
测试一下表格 的中文 |
Header row, column 1 (header rows optional) | Header 2 | Header 3 | Header 4 |
---|---|---|---|
body row 1, column 1 | column 2 | column 3 | column 4 |
body row 2 | Cells may span columns. | ||
body row 3 | Cells may span rows. |
|
|
body row 4 |
姓名 | 年龄 |
---|---|
陈小明 | 27 |
姓名 | 年龄 |
张三丰 | 18 |
简单表:
Inputs | Output | |
---|---|---|
A | B | A or B |
False | False | False |
True | False | True |
False | True | True |
True | True | True |
CSV Table
待续
保留换行符
脚注 Footnotes
- 使用 [#name]_ 来标记位置, 并在文章底部 “Footnotes” 专栏之后追加脚注内容,如下使用:
脚注参考,用了rubric标记
[1] | 这是脚本1的参考 |
[2] | 这是脚本2的参考 |
- 也可以使用确切编号的脚注 (如: [1]_) 或是自动编号(用 [#]_).
脚注参考,用了rubric标记
[3] 这是脚本1的参考
[4] 这是脚本2的参考
[5] 注意上文 用 数字 的例子即 [#数字]_,不要忘记前后 空格
数字脚注
[6] 11号脚注
[7] 12号脚注
引证 Citations
类似脚注,不同的是没有 `#` ,如:
这是我喜欢的一本书,《挪威的森林》 [ref] ,还是那句话不要忘记前后的 空格 ,特别是中文时的 ” 》 ” 会让人产生错觉,其实那后面还没有空格的。
引证
[ref] | 村上春树写于1987年的一本青春恋爱小说 |
替换替换 Substitutions
reST 支持 “替换” (参考), 以 |name| 形式来定义替换的文本或是标记对象. 如脚注,可以在直解标记文本块中声明, 也可以使用图像,函数或其他,详细可见 此链接
我的名字叫 Falcon Chen [ blog ] ,我不喜欢这个 ,我在学习 reStructedText 和 Sphinx
Sphinx增加的 标记
这里有详细说明( ref)
以下为rst格式:
===============================================
RestStructedText 实例练习篇
===============================================
:Author: Falcon Chen
:Contact: falcon_chen@qq.com
:Date: $Date$
:Copyright: public
.. contents::
.. tip:: 一个非常好的 `在线练习工具`__
__ http://www.hosting4u.cz/jbar/rest/rest.html
匿名链接
===============================================
这是 `匿名链接`__,然后这个是 `按名称链接`_,链接与目标之间有 **空行** 。**前后有空格,特别注意`前面也要有空格。
__ #
.. _按名称链接: http://www.realworld.com
列表
===============================================
有序列表
--------------------------------------------------------------------------------------
1. 一级项目1
(1) 缩进的二级项目1
1. 三级项目1(貌似无效)
2. 三级项目2
3. 三级项目3
(2) 缩进的二级项目2
2. 一级项目2
3. 一级项目3
无序列表
--------------------------------------------------------------------------------------
* 无序项目一级1
- 无序项目二级1
- 无序项目二级2
+无序项目3
* 无序项目一级2
定义
--------------------------------------------------------------------------------------
(definition__)
什么
定义是描述一个事物的专用术语
*如何*
如何是这样那样
哈哈。。。
__
预格式化
===============================================
(prefomatting__)
例子开始::
特殊字符
如(**这里**)或者不被转义
注意例子开始与结束的:: 号,空行还有相同的缩进
例子结束
__
图像
===============================================
(images__)
.. image:: http://www.zerodm.cn/template/heiku/images/logo.png
:height: 100
:width: 200
:scale: 50
:alt: Zero动漫
:align: center
:target: http://www.zerodm.cn
__
特殊指令
===============================================
:指令类型: "attention","caution","danger","error","hint","important","note","tip","warning","admonition"
:example 1:
.. danger:: Don't Do this!
:example 2: (缩进的部分会作为子部分加入段落)
.. note:: 这是note指令
第一个段落的第二行,注意 *缩进* 和 **空行**
- 列表项目1
仍然是列表的内容,使用缩进
- 列表项目2
:指令元素: attention, caution, danger, error, hint, important, note, tip, warning,title
:指令选项: `:class:`__ , `:name:`__
:指令内容: 会当作主体(body)元素解析
__
__
figure
===============================================
figure包含image的数据,包括 image options 和可选的标题(caption)
.. figure:: http://t2.qlogo.cn/mbloghead/86c019687df2a273a9c0/100
:align: center
:figwidth: 50%
:figclass: people-head
:alt: 我的头像
.. note::
figure与image有区别的,figure是包括了标题的,在解析为html时,figure的image元素会被div所包裹。如 ::
.. figure:: picture.png
:scale: 50 %
:alt: map to buried treasure
.. image:: picture.png
:scale: 50 %
:alt: map to buried treasure
html解析::
Body元素
===============================================
topic
--------------------------------------------------------------------------------------
.. topic:: 这是话题标题
此为内容
仍然是内容,下一段落
.. note::
:class和:name属性不可用?
sidebar
--------------------------------------------------------------------------------------
.. sidebar:: 侧边栏标题
:subtitle: 可选的侧边栏子标题
以下为内容,会被浮动
内容啊内容
* 内容列表
+ 111
+ 222
Line Block(行内块)
--------------------------------------------------------------------------------------
.. line-block::
原生解析,
God Bless You!
Parsed Literal Block(块原生解析)
--------------------------------------------------------------------------------------
这个不做实际解析了,用法如下::
.. parsed-literal::
( (title_, subtitle_?)?,
decoration_?,
(docinfo_, transition_?)?,
`%structure.model;`_ )
Code (Docutils 0.9新增,使用了 Pygments_ 做语法高亮)
--------------------------------------------------------------------------------------
用法如下::
.. code:: python
def my_function():
"just a test"
print 8/2
.. _Pygments: http://pygments.org/
Epigraph
--------------------------------------------------------------------------------------
.. epigraph::
再见青春,再见美丽的疼痛。
——《汪峰-再见青春》
Compound
--------------------------------------------------------------------------------------
.. compound::
The 'rm' command is very dangerous. If you are logged
in as root and enter ::
cd /
rm -rf *
you will erase the entire contents of your file system.
Table
--------------------------------------------------------------------------------------
.. caution::
请务必使用等宽字体进行表格的编写,不然你就会遇到跟我一样的各种莫名其妙的坑爹事!
推荐字体:Lucida Console ,文泉驿等宽微米黑(`下载`__) 虽然也是等宽,但是在中文下也有视觉错误
test:
+-------------+
|测试中文 |
+=============+
|测试一下表格 |
|的中文 |
| |
+-------------+
+------------------------+------------+----------+----------+
| Header row, column 1 | Header 2 | Header 3 | Header 4 |
| (header rows optional) | | | |
+========================+============+==========+==========+
| body row 1, column 1 | column 2 | column 3 | column 4 |
+------------------------+------------+----------+----------+
| body row 2 | Cells may span columns. |
+------------------------+------------+---------------------+
| body row 3 | Cells may | - Table cells |
+------------------------+ span rows. | - contain |
| body row 4 | | - body elements. |
+------------------------+------------+---------------------+
+------------------------+---------------------+
| 姓名 | 年龄 |
+========================+=====================+
| 陈小明 | 27 |
+------------------------+---------------------+
====== ======
姓名 年龄
------ ------
张三丰 18
====== ======
简单表:
===== ===== ======
Inputs Output
------------ ------
A B A or B
===== ===== ======
False False False
True False True
False True True
True True True
===== ===== ======
__ http://ishare.iask.sina.com.cn/f/17402752.html?retcode=0
CSV Table
--------------------------------------------------------------------------------------
待续
保留换行符
--------------------------------------------------------------------------------------
| 保留换行符测试,行一
| 行二
| 再来一行
脚注 Footnotes
--------------------------------------------------------------------------------------
1. 使用 `[#name]_` 来标记位置, 并在文章底部 “Footnotes” 专栏之后追加脚注内容,如下使用:
这是 [#脚本1]_ ,这是 [#脚本2]_
.. rubric:: 脚注参考,用了rubric标记
.. [#脚本1] 这是脚本1的参考
.. [#脚本2] 这是脚本2的参考
2. 也可以使用确切编号的脚注 (如: `[1]_`) 或是自动编号(用 `[#]_`).
| 这是脚本 [#]_ ,这是 第二个 [#]_
| 但是要注意的是 `[#x]_` 后面是有空格或者换行符的 [#]_ ,`也是一样,不能忽略后面的空格
.. rubric:: 脚注参考,用了rubric标记
.. [#] 这是脚本1的参考
.. [#] 这是脚本2的参考
.. [#] 注意上文
用 *数字* 的例子即 `[#数字]_`,不要忘记前后 **空格**
| 这里使用数字 [#11]_
| 这里使用另一个数字 [#12]_
.. rubric:: 数字脚注
.. [#11] 11号脚注
.. [#12] 12号脚注
引证 Citations
--------------------------------------------------------------------------------------
类似脚注,不同的是没有 **`#`** ,如:
这是我喜欢的一本书,《挪威的森林》 [ref]_ ,还是那句话不要忘记前后的 **空格** ,特别是中文时的 " *》* " 会让人产生错觉,其实那后面还没有空格的。
.. rubric:: 引证
.. [ref] 村上春树写于1987年的一本青春恋爱小说
替换替换 Substitutions
--------------------------------------------------------------------------------------
reST 支持 “替换” (参考), 以 `|name|` 形式来定义替换的文本或是标记对象. 如脚注,可以在直解标记文本块中声明, 也可以使用图像,函数或其他,详细可见 `此链接`__
我的名字叫 |name| ,我不喜欢这个 |百度搜索|__ ,我在学习 |reST| 和 Sphinx
.. |name| replace:: **Falcon Chen** [ blog_ ]
.. |百度搜索| image:: http://www.baidu.com/img/baidu_jgylogo3.gif
:alt: 百度搜索
.. |reSt| replace:: **reStructedText**
__ http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#substitution-definitions
__ http://www.baidu.com
.. _blog: http://www.onephper.tk
自定义标记
--------------------------------------------------------------------------------------
`role参考`__
.. role:: custom (literal)
:custom: 我是谁
__ http://docutils.sourceforge.net/docs/ref/rst/roles.html
特殊角色标志(如公式的上下标)
--------------------------------------------------------------------------------------
H :sub:`2` O
E = mc :sup:`2`
注释
--------------------------------------------------------------------------------------
可用缩进的方法进行多行注释::
..
多行注释
行二
行三
Sphinx增加的 标记
--------------------------------------------------------------------------------------
这里有详细说明( ref_)
.. _link: http://readthedocs.org/docs/sphinx-doc-zh/en/latest/markup/index.html#sphinxmarkup