markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(john gruber)。 它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的 xhtml(或者html)文档。这种语言吸收了很多在电子邮件中已有的纯文本标记的特性。
由于 markdown 的轻量化、易读易写特性,并且对于图片,图表、数学式都有支持,许多网站都广泛使用 markdown 来撰写帮助文档或是用于论坛上发表消息。 如 github、reddit、diaspora、stack exchange、openstreetmap 、sourceforge、简书等,甚至还能被使用来撰写电子书。
几乎所有markdown应用程序都支持john gruber原始设计文档中概述的基本语法。markdown处理器之间存在细微的差异和差异-尽可能在线内注明。
标题
要创建标题,请#
在单词或短语的前面添加数字符号()。您使用的数字符号的数量应与标题级别相对应。例如,要创建标题级别三(<h3>
),请使用三个数字符号(例如### my header
)。
markdown | html | |
---|---|---|
# heading level 1 | <h1>heading level 1</h1> | |
## heading level 2 | <h2>heading level 2</h2> | |
### heading level 3 | <h3>heading level 3</h3> | |
#### heading level 4 | <h4>heading level 4</h4> | |
##### heading level 5 | <h5>heading level 5</h5> | |
###### heading level 6 | <h6>heading level 6</h6> |
替代语法
或者,在文本下方的行上,添加任意数量的==
标题级别1的--
字符或标题级别2的字符。
markdown | html | |
---|---|---|
heading level 1 | <h1>heading level 1</h1> | |
heading level 2 | <h2>heading level 2</h2> |
段落
要创建段落,请使用空白行分隔一行或多行文本。您不应缩进带有空格或制表符的段落。
markdown | html | |
---|---|---|
i really like using markdown. | <p>i really like using markdown.</p> |
换行
要创建换行符(<br>
),请以两个或多个空格结束一行,然后键入return。
markdown | html | |
---|---|---|
this is the first line. | <p>this is the first line.<br> |
着重
您可以通过使文本变为粗体或斜体来增加着重。
粗体
要加粗文本,请在单词或短语的前后添加两个星号或下划线。要加粗一个单词的中部以强调,请在字母周围添加两个星号,且各空格之间不加空格。
markdown | html | 渲染输出 |
---|---|---|
i just love **bold text**. | i just love <strong>bold text</strong>. | 我只喜欢粗体字。 |
i just love __bold text__. | i just love <strong>bold text</strong>. | 我只喜欢粗体字。 |
love**is**bold | love<strong>is</strong>bold | 爱是大胆的 |
斜体
要斜体显示文本,请在单词或短语的前后添加一个星号或下划线。要斜体突出单词的中间部分,请在字母周围添加一个星号,中间不要带空格。
markdown | html | 渲染输出 |
---|---|---|
italicized text is the *cat's meow*. | italicized text is the <em>cat's meow</em>. | 斜体文字是猫的叫声。 |
italicized text is the _cat's meow_. | italicized text is the <em>cat's meow</em>. | 斜体文字是猫的叫声。 |
a*cat*meow | a<em>cat</em>meow | 一个猫喵 |
粗体和斜体
要同时突出显示带有粗体和斜体的文本,请在单词或短语的前后添加三个星号或下划线。
markdown | html | 渲染输出 |
---|---|---|
this text is ***really important***. | this text is <strong><em>really important</em></strong>. | 这段文字真的很重要。 |
this text is ___really important___. | this text is <strong><em>really important</em></strong>. | 这段文字真的很重要。 |
this text is __*really important*__. | this text is <strong><em>really important</em></strong>. | 这段文字真的很重要。 |
this text is **_really important_**. | this text is <strong><em>really important</em></strong>. | 这段文字真的很重要。 |
块引用
要创建blockquote,请>
在段落前面添加一个。
> dorothy followed her through many of the beautiful rooms in her castle.
呈现的输出如下所示:
桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。
具有多个段落的块引用
块引用可以包含多个段落。>
在段落之间的空白行上添加一个。
> dorothy followed her through many of the beautiful rooms in her castle. > > the witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
呈现的输出如下所示:
桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。
女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。
嵌套块引用
块引用可以嵌套。>>
在要嵌套的段落前面添加一个。
> dorothy followed her through many of the beautiful rooms in her castle. > >> the witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.
呈现的输出如下所示:
桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。
女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。
具有其他元素的块引用
块引用可以包含其他markdown格式的元素。并非所有元素都可以使用-您需要进行实验以查看哪些元素有效。
> #### the quarterly results look great! > > - revenue was off the chart. > - profits were higher than ever. > > *everything* is going according to **plan**.
呈现的输出如下所示:
季度业绩看起来不错!
- 收入超出了预期。
- 利润比以往任何时候都高。
一切都按计划进行。
清单
您可以将项目组织成有序和无序列表。
有序列表
要创建有序列表,请在订单项中添加数字和句点。数字不必按数字顺序排列,但列表应以数字开头。
markdown | html | 渲染输出 |
---|---|---|
1. first item | <ol> |
|
1. first item | <ol> |
|
1. first item | <ol> |
|
1. first item | <ol> |
|
无序列表
要创建无序列表,请在订单项前添加破折号(-
),星号(*
)或加号(+
)。缩进一个或多个项目以创建嵌套列表。
markdown | html | 渲染输出 |
---|---|---|
- first item | <ul> |
|
* first item | <ul> |
|
+ first item | <ul> |
|
- first item | <ul> |
|
在列表中添加元素
要在保留列表连续性的同时在列表中添加另一个元素,请将该元素缩进四个空格或一个制表符,如以下示例所示。
段落
* this is the first list item. * here's the second list item. i need to add another paragraph below the second list item. * and here's the third list item.
呈现的输出如下所示:
- 这是第一个列表项。
这是第二个列表项。
我需要在第二个列表项下面添加另一段。
- 这是第三个列表项。
块引用
* this is the first list item. * here's the second list item. > a blockquote would look great below the second list item. * and here's the third list item.
呈现的输出如下所示:
- 这是第一个列表项。
这是第二个列表项。
在第二个列表项的下方,blockquote看起来不错。
- 这是第三个列表项。
代码块
代码块通常缩进四个空格或一个制表符。当它们在列表中时,将它们缩进八个空格或两个选项卡。
1. open the file. 2. find the following code block on line 21: <html> <head> <title>test</title> </head> 3. update the title to match the name of your website.
呈现的输出如下所示:
- 打开文件。
在第21行找到以下代码块:
<html> <head> <title>test</title> </head>
- 更新标题以匹配您的网站名称。
图片
1. open the file containing the linux mascot. 2. marvel at its beauty.  3. close the file.
呈现的输出如下所示:
- 打开包含linux吉祥物的文件。
惊叹于它的美丽。
- 关闭文件。
代码
要将单词或短语表示为代码,请将其括在勾号(`
)中。
markdown | html | 渲染输出 |
---|---|---|
at the command prompt, type `nano`. | at the command prompt, type <code>nano</code>. | 在命令提示符下,键入nano 。 |
转义刻度线
如果要表示为代码的单词或短语包含一个或多个刻度线,可以通过将单词或短语括在双刻度线(``
)中来对其进行转义。
markdown | html | 渲染输出 |
---|---|---|
``use `code` in your markdown file.`` | <code>use `code` in your markdown file.</code> | use `code` in your markdown file. |
代码块
要创建代码块,请在代码块的每一行缩进至少四个空格或一个制表符。
<html> <head> </head> </html>
呈现的输出如下所示:
<html> <head> </head> </html>
水平线
要创建水平线***
,请单独在一行上使用三个或更多的星号(),破折号(---
)或下划线(___
)。
*** --- _________________
所有这三个的渲染输出看起来都相同:
链接
要创建链接,请将链接文本括在方括号(例如[duck duck go]
)中,然后立即在url后面加上括号(例如(https://duckduckgo.com)
)中的url 。
my favorite search engine is [duck duck go](https://duckduckgo.com).
呈现的输出如下所示:
我最喜欢的搜索引擎是duck duck go。
添加标题
您可以选择为链接添加标题。当用户将鼠标悬停在链接上时,这将显示为工具提示。要添加标题,请将其括在url后面的括号中。
my favorite search engine is [duck duck go](https://duckduckgo.com "the best search engine for privacy").
呈现的输出如下所示:
我最喜欢的搜索引擎是duck duck go。
网址和电子邮件地址
要将url或电子邮件地址快速转换为链接,请将其括在尖括号中。
<https://markdown.p2hp.com> <fake@example.com>
呈现的输出如下所示:
https://markdown.p2hp.com
fake@example.com
格式化链接
为了强调链接,请在方括号和括号之前和之后添加星号。
i love supporting the **[eff](https://eff.org)**. this is the *[markdown guide](https://markdown.p2hp.com)*.
呈现的输出如下所示:
我喜欢支持eff。
这是《markdown指南》。
参考样式链接
引用样式链接是一种特殊的链接,它使url在markdown中更易于显示和阅读。引用样式的链接分为两部分:与文本保持内联的部分以及在文件中其他位置存储的部分,以使文本易于阅读。
格式化链接的第一部分
参考样式链接的第一部分使用两组括号进行格式化。第一组方括号包围应显示为链接的文本。第二组括号显示了一个标签,该标签用于指向您存储在文档其他位置的链接。
尽管不是必需的,但您可以在第一组和第二组支架之间包含一个空格。第二组括号中的标签不区分大小写,可以包含字母,数字,空格或标点符号。
这意味着以下示例格式对于链接的第一部分大致相同:
[hobbit-hole][1]
[hobbit-hole] [1]
格式化链接的第二部分
引用样式链接的第二部分使用以下属性设置格式:
- 标签放在方括号中,后紧跟冒号和至少一个空格(例如
[label]:
)。 - 链接的url,您可以选择将其括在尖括号中。
- 链接的可选标题,您可以将其括在双引号,单引号或括号中。
这意味着以下示例格式对于链接的第二部分几乎都是等效的:
[1]: https://en.wikipedia.org/wiki/hobbit#lifestyle
[1]: https://en.wikipedia.org/wiki/hobbit#lifestyle "hobbit lifestyles"
[1]: https://en.wikipedia.org/wiki/hobbit#lifestyle 'hobbit lifestyles'
[1]: https://en.wikipedia.org/wiki/hobbit#lifestyle (hobbit lifestyles)
[1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> "hobbit lifestyles"
[1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> 'hobbit lifestyles'
[1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> (hobbit lifestyles)
您可以将链接的第二部分放在markdown文档中的任何位置。有些人将它们放在出现的段落之后,而其他人则将它们放在文档的末尾(例如尾注或脚注)。
将零件放在一起的示例
假设您添加一个url作为到段落的标准url链接,并且在markdown中看起来像这样:
in a hole in the ground there lived a hobbit. not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a [hobbit-hole](https://en.wikipedia.org/wiki/hobbit#lifestyle "hobbit lifestyles"), and that means comfort.
尽管它可能指向有趣的附加信息,但显示的url确实不会给现有的原始文本增加太多,除了使其难以阅读之外。要解决此问题,您可以改为设置网址格式:
in a hole in the ground there lived a hobbit. not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a [hobbit-hole][1], and that means comfort. [1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> "hobbit lifestyles"
在上述两种情况下,呈现的输出将相同:
在地上的一个洞里住着一个霍比特人。这不是一个肮脏,肮脏,潮湿的洞,里面充满蠕虫的末端和难闻的气味,也没有一个干燥,裸露,沙质的洞,里面没有东西可以坐下或进食:那是一个霍比特洞,意味着舒适。
链接html为:
<a href="https://en.wikipedia.org/wiki/hobbit#lifestyle" rel="external nofollow" title="hobbit lifestyles">hobbit-hole</a>
图片
要添加图像,请添加感叹号(!
),然后在括号中添加替代文本,并在括号中添加图像资源的路径或url。您可以选择在括号中的url之后添加标题。

呈现的输出如下所示:
链接图像
要向图像添加链接,请将图像的markdown括在方括号中,然后在括号中添加链接。
[](https://www.flickr.com/photos/beaurogers/31833779864/in/photolist-qv3rfw-34mt9f-a9cmfy-5ha3zi-9mskdv-o3hgjr-hwpute-4wmsj1-kuq8n-deshub-vssbd-6cqci6-8afcid-zsjwt-nnfsgb-dpdwzj-bn9jgn-5htsxy-6cuhal-a4utxb-ugpum-kupso-fblnm-6cumpy-4wmsc9-8a7d3t-83kjev-6cq2bk-nnushj-a78rqh-nw3nvt-7aq2qf-8wwbso-3nnceh-ugskp-4mh4kh-bbeeqh-a7bime-q3pttf-brfpgb-cg38zw-bxmzc-njpeld-f58lmo-bxmyg-bz8aai-bxntnt-bxmyi-bxmy6-bxmyv)
呈现的输出如下所示:
转义字符
要显示原义字符,否则将用于设置markdown文档中的文本格式\
,请在字符前面添加反斜杠()。
\* without the backslash, this would be a bullet in an unordered list.
呈现的输出如下所示:
*如果没有反斜杠,这将是无序列表中的项目符号。
你可以转义的字符
您可以使用反斜杠转义以下字符。
字符 | 名称 |
---|---|
\ | 反斜杠 |
` | 刻度线 |
* | 星号 |
_ | 下划线 |
{} | 大括号 |
[] | 中括号 |
() | 括号 |
# | 井号 |
+ | 加号 |
- | 减号(连字符) |
. | 点 |
! | 感叹号 |
| | 管道 |
发表评论