Markdown 语法指南
格式化文档的基本语法
概述
Markdown 是一种轻量级标记语言,用于为纯文本文档添加格式。由 John Gruber 于 2004 年创建,现已成为全球最流行的标记语言之一。
使用 Markdown 不同于 WYSIWYG 编辑器。在 Word 等应用中,你点击按钮格式化文字,效果立即可见。Markdown 不同:你在文本中加入 Markdown 语法,标出哪些词、句应显示不同。
标题
在词或短语前加 # 创建标题。# 的数量对应标题级别(例如 ### 为三级标题)。
Heading level 1
Heading level 2
Heading level 3
Heading level 4
Heading level 5
Heading level 6
段落
用空行分隔一行或多行文字即可形成段落。
It lets me write easily.
<p>It lets me write easily.</p>
I really like using Markdown.
It lets me write easily.
换行
行末加两个或多个空格再回车即可换行。
And this is the second line.
And this is the second line.</p>
This is the first line.
And this is the second line.
强调
可通过加粗或斜体强调文字。
粗体
在词或短语前后加 ** 或 __ 即可加粗。
I just love bold text.
I just love bold text.
斜体
在词或短语前后加 * 或 _ 即可斜体。
The cat meows.
The cat meows.
粗体与斜体
在词或短语前后加 *** 或 ___ 即可同时加粗和斜体。
This text is really important.
This text is really important.
引用
在段落前加 > 即可创建引用。
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 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.
列表
可将项目组织为有序或无序列表。
有序列表
每行以数字加句点开头即可创建有序列表。数字不必连续,但列表应从 1 开始。
2. Second item
3. Third item
4. Fourth item
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>
- First item
- Second item
- Third item
- Fourth item
无序列表
在每行前加 -、* 或 + 即可创建无序列表。
- Second item
- Third item
- Fourth item
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>
- First item
- Second item
- Third item
- Fourth item
代码
用反引号 ` 将词或短语围住即可标记为代码。
At the command prompt, type nano.
代码块
每行缩进至少四个空格或一个制表符,或在代码块前后用 ``` 围住,即可创建代码块。
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}水平线
单独一行使用三个及以上 ***、--- 或 ___ 即可创建水平线。
链接
用 [链接文字] 包住文字,紧接 (URL),例如 [Duck Duck Go](https://duckduckgo.com)。
My favorite search engine is Duck Duck Go.
添加标题
可为链接可选添加标题,鼠标悬停时显示为工具提示。在 URL 后加引号包住标题即可。
My favorite search engine is Duck Duck Go.
图片
添加图片:先写 !,再写 [替代文字],最后在括号里写图片路径或 URL。可选在 URL 后加引号包住的标题。

转义字符
若要显示本用于格式化的字符本义,在该字符前加反斜杠 \。
* Without the backslash, this would be a bullet in an unordered list.
可转义的字符
可用反斜杠转义以下字符:
| \ | backslash |
| ` | backtick |
| * | asterisk |
| _ | underscore |
| { } | curly braces |
| [ ] | brackets |
| ( ) | parentheses |
| # | pound sign |
| + | plus sign |
| - | minus sign (hyphen) |
| . | dot |
| ! | exclamation mark |
| | | pipe |
表格
用三个及以上 --- 做每列表头,用 | 分隔列。可选在表格两端也加 |。
| --------- | ----------- |
| Header | Title |
| Paragraph | Text |
| Syntax | Description |
|---|---|
| Header | Title |
| Paragraph | Text |
对齐
在表头行的连字符左侧、右侧或两侧加冒号 (:) 可分别左对齐、右对齐或居中对齐列内文字。
| :--- | :---: | ---: |
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |
| 左对齐 | 居中 | 右对齐 |
|---|---|---|
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |