原始设计文档中概述的 Markdown 元素。
几乎所有 Markdown 应用程序都支持原始 Markdown 设计文档中概述的基本语法。Markdown 处理器之间存在细微的差异和差异 — 这些变化和差异会尽可能以内联方式注明。
要创建标题,请在单词或短语前面添加数字符号 ()。您使用的数字符号数量应与标题级别相对应。例如,要创建标题级别 3 (),请使用三个数字符号(例如 )。#
<h3>
### My Header
Markdown | HTML | 渲染输出 |
---|---|---|
# Heading level 1 |
<h1>Heading level 1</h1> |
标题级别 1 |
## Heading level 2 |
<h2>Heading level 2</h2> |
标题级别 2 |
### Heading level 3 |
<h3>Heading level 3</h3> |
标题级别 3 |
#### Heading level 4 |
<h4>Heading level 4</h4> |
标题级别 4 |
##### Heading level 5 |
<h5>Heading level 5</h5> |
标题级别 5 |
###### Heading level 6 |
<h6>Heading level 6</h6> |
标题级别 6 |
或者,在文本下方的行中,为标题级别 1 添加任意数量的字符,或为标题级别 2 添加任意数量的字符。==
--
Markdown | HTML | 渲染输出 |
---|---|---|
Heading level 1 |
<h1>Heading level 1</h1> |
标题级别 1 |
Heading level 2 |
<h2>Heading level 2</h2> |
标题级别 2 |
Markdown 应用程序在如何处理数字符号 () 和标题名称之间缺少的空格方面没有达成一致。为了兼容性,请始终在数字符号和标题名称之间放置一个空格。#
✅ 执行此作 | ❌ 别这样 |
---|---|
# Here's a Heading
|
#Here's a Heading
|
您还应该在标题前后放置空行以实现兼容性。
✅ 执行此作 | ❌ 别这样 |
---|---|
Try to put a blank line before...
|
Without blank lines, this might not look right.
|
要创建段落,请使用空行分隔一行或多行文本。
Markdown | HTML | 渲染输出 |
---|---|---|
I really like using Markdown.
|
<p>I really like using Markdown.</p>
|
我真的很喜欢使用 Markdown。 我想从现在开始我将使用它来格式化我的所有文档。 |
除非段落位于列表中,否则不要使用空格或制表符缩进段落。
✅ 执行此作 | ❌ 别这样 |
---|---|
Don't put tabs or spaces in front of your paragraphs.
|
This can result in unexpected
formatting problems.
|
若要创建换行符或换行符 (),请以两个或多个空格结束一行,然后键入 return。<br>
Markdown | HTML | 渲染输出 |
---|---|---|
This is the first line.
|
<p>This is the first line.<br>
|
这是第一行。 |
在几乎每个 Markdown 应用程序中,你都可以使用两个或多个空格(通常称为“尾随空格”)作为换行符,但这是有争议的。在编辑器中很难看到尾随空格,许多人无意中或有意地在每个句子后放置两个空格。因此,您可能希望使用尾随空格以外的其他内容来换行。如果您的 Markdown 应用程序支持 HTML,则可以使用 HTML 标签。<br>
为了兼容性,请在行尾使用尾随空格或 HTML 标记。<br>
我不建议使用其他两个选项。CommonMark 和其他一些轻量级标记语言允许您在行尾键入反斜杠 (),但并非所有 Markdown 应用程序都支持此功能,因此从兼容性的角度来看,它不是一个好的选择。至少一些轻量级的标记语言不需要在行尾做任何事情 — 只需键入 return ,它们就会创建一个换行符。\
✅ 执行此作 | ❌ 别这样 |
---|---|
First line with two spaces after.
|
First line with a backslash after.\
|
您可以通过将文本设为粗体或斜体来添加强调。
要加粗文本,请在单词或短语前后添加两个星号或下划线。要将单词的中间加粗以强调,请添加两个星号,字母周围不带空格。
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 应用程序在如何处理单词中间的下划线方面没有达成一致。为了兼容性,请使用星号将单词的中间加粗以强调。
✅ 执行此作 | ❌ 别这样 |
---|---|
Love**is**bold
|
Love__is__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 应用程序在如何处理单词中间的下划线方面没有达成一致。为了兼容性,请使用星号将单词的中间斜体化以强调。
✅ 执行此作 | ❌ 别这样 |
---|---|
A*cat*meow
|
A_cat_meow
|
要同时强调粗体和斜体文本,请在单词或短语前后添加三个星号或下划线。要将单词的中间加粗和斜体以强调,请添加三个星号,字母周围没有空格。
Markdown | HTML | 渲染输出 |
---|---|---|
This text is ***really important***. |
This text is <em><strong>really important</strong></em>. |
这段文字真的很重要。 |
This text is ___really important___. |
This text is <em><strong>really important</strong></em>. |
这段文字真的很重要。 |
This text is __*really important*__. |
This text is <em><strong>really important</strong></em>. |
这段文字真的很重要。 |
This text is **_really important_**. |
This text is <em><strong>really important</strong></em>. |
这段文字真的很重要。 |
This is really***very***important text. |
This is really<em><strong>very</strong></em>important text. |
这确实是非常重要的文本。 |
em
strong
Markdown 应用程序在如何处理单词中间的下划线方面没有达成一致。为了兼容性,请使用星号将单词的中间加粗和斜体以强调。
✅ 执行此作 | ❌ 别这样 |
---|---|
This is really***very***important text.
|
This is really___very___important text.
|
要创建块引用,请在段落前面添加 a。>
> Dorothy followed her through many of the beautiful rooms in her castle.
渲染的输出如下所示:
多萝西跟着她穿过了她城堡里许多漂亮的房间。
块引用可以包含多个段落。在段落之间的空行上添加 a。>
> 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.
渲染的输出如下所示:
多萝西跟着她穿过了她城堡里许多漂亮的房间。
女巫吩咐她把锅和水壶打扫干净,扫地,用柴火生火。
块引用可以包含其他 Markdown 格式的元素。并非所有元素都可以使用 — 您需要尝试看看哪些元素有效。
> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
> *Everything* is going according to **plan**.
渲染的输出如下所示:
季度结果看起来很棒!
- 收入超出图表。
- 利润比以往任何时候都高。
一切都在按计划进行。
为了兼容性,请在块引用之前和之后放置空行。
✅ 执行此作 | ❌ 别这样 |
---|---|
Try to put a blank line before...
|
Without blank lines, this might not look right.
|
您可以将项目组织成有序列表和无序列表。
要创建有序列表,请添加带有数字后跟句点的行项目。数字不必按数字顺序排列,但列表应以数字 1 开头。
Markdown | HTML | 渲染输出 |
---|---|---|
1. First item
|
<ol>
|
|
1. First item
|
<ol>
|
|
1. First item
|
<ol>
|
|
1. First item
|
<ol>
|
|
CommonMark 和其他一些轻量级标记语言允许您使用括号 () 作为分隔符(例如,),但并非所有 Markdown 应用程序都支持此功能,因此从兼容性的角度来看,它不是一个好的选择。为了兼容性,请仅使用 period。)
1) First item
✅ 执行此作 | ❌ 别这样 |
---|---|
1. First item
|
1) First item
|
要创建无序列表,请在行项目前面添加短划线 ()、星号 () 或加号 ()。缩进一个或多个项目以创建嵌套列表。-
*
+
Markdown | HTML | 渲染输出 |
---|---|---|
- First item
|
<ul>
|
|
* First item
|
<ul>
|
|
+ First item
|
<ul>
|
|
- First item
|
<ul>
|
|
如果需要以数字后跟句点开始无序列表项,可以使用反斜杠 () 来转义句点。\
Markdown | HTML | 渲染输出 |
---|---|---|
- 1968\. A great year!
|
<ul>
|
|
Markdown 应用程序在如何处理同一列表中的不同分隔符方面没有达成一致。为了兼容性,不要在同一个列表中混合和匹配分隔符 - 选择一个并坚持使用。
✅ 执行此作 | ❌ 别这样 |
---|---|
- First item
|
+ First item
|
要在列表中添加另一个元素,同时保持列表的连续性,请将元素缩进 4 个空格或 1 个制表符,如以下示例所示。
* 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.
渲染的输出如下所示:
这是第二个列表项。
块引用在第二个列表项下方看起来会很棒。
代码块通常缩进四个空格或 1 个制表符。当它们位于列表中时,将它们缩进 8 个空格或 2 个制表符。
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.
渲染的输出如下所示:
惊叹于它的美丽。
您可以将无序列表嵌套在有序列表中,反之亦然。
1. First item
2. Second item
3. Third item
- Indented item
- Indented item
4. Fourth item
渲染的输出如下所示:
要将单词或短语表示为 code,请将其括在反引号 () 中。`
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. |
要创建代码块,请将代码块的每一行缩进至少 4 个空格或 1 个制表符。
<html>
<head>
</head>
</html>
渲染的输出如下所示:
<html>
<head>
</head>
</html>
要创建水平标尺,请在一行上单独使用三个或三个以上的星号 ()、短划线 () 或下划线 ()。***
---
___
***
---
_________________
所有三个的渲染输出看起来都相同:
为了兼容性,请在水平线之前和之后放置空行。
✅ 执行此作 | ❌ 别这样 |
---|---|
Try to put a blank line before...
|
Without blank lines, this would be a heading.
|
要创建链接,请将链接文本括在括号中(例如,),然后紧随其后,将 URL 括在括号中(例如,)。[Duck Duck Go]
(https://duckduckgo.com)
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://www.markdownguide.org>
<fake@example.com>
渲染的输出如下所示:
https://www.markdownguide.org fake@example.com
要强调链接,请在方括号和圆括号前后添加星号。要将链接表示为代码,请在括号中添加反引号。
I love supporting the **[EFF](https://eff.org)**.
This is the *[Markdown Guide](https://www.markdownguide.org)*.
See the section on [`code`](#code).
渲染的输出如下所示:
我喜欢支持 EFF。
这是 Markdown 指南。
请参阅有关代码
的部分。
引用样式链接是一种特殊类型的链接,它使 URL 在 Markdown 中更易于显示和阅读。引用样式链接由两部分构成:与文本保持内联的部分和存储在文件中的其他位置以保持文本易于阅读的部分。
引用样式链接的第一部分使用两组括号进行格式化。第一组括号括起来,应该显示为链接的文本。第二组括号显示一个标签,用于指向您存储在文档其他位置的链接。
虽然不是必需的,但您可以在第一组和第二组括号之间包含一个空格。第二组括号中的标签不区分大小写,可以包含字母、数字、空格或标点符号。
这意味着以下示例格式与链接的第一部分大致等效:
[hobbit-hole][1]
[hobbit-hole] [1]
引用样式链接的第二部分使用以下属性进行格式设置:
[label]:
这意味着以下示例格式与链接的第二部分大致等效:
[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 除了使其更难阅读之外,实际上并没有对现有的原始文本增加太多。要解决此问题,您可以改为将 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" title="Hobbit lifestyles">hobbit-hole</a>
Markdown 应用程序在如何处理 URL 中间的空格方面没有达成一致。为了兼容性,请尝试使用 .或者,如果您的 Markdown 应用程序支持 HTML,则可以使用 HTML 标记。%20
a
✅ 执行此作 | ❌ 别这样 |
---|---|
[link](https://www.example.com/my%20great%20page)
|
[link](https://www.example.com/my great page)
|
URL 中间的括号也可能有问题。为了兼容性,请尝试对左括号 () 进行 URL 编码,将右括号 () 进行 URL 编码。或者,如果您的 Markdown 应用程序支持 HTML,则可以使用 HTML 标记。(
%28
)
%29
a
✅ 执行此作 | ❌ 别这样 |
---|---|
[a novel](https://en.wikipedia.org/wiki/
|
[a novel](https://en.wikipedia.org/wiki/
|
要添加图片,请添加感叹号 (),后跟括号中的 alt 文本,并在括号中添加图片资产的路径或 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.
渲染的输出如下所示:
* 如果没有反斜杠,这将是无序列表中的项目符号。
您可以使用反斜杠对以下字符进行转义。
字符 | 名字 |
---|---|
\ | 反斜线 |
` | 反引号(另请参阅在代码中转义反引号) |
* | 星号 |
_ | 强调 |
{ } | 大括号 |
[ ] | 括弧 |
< > | 尖括号 |
( ) | 括弧 |
# | 井号 |
+ | 加号 |
- | 减号(连字符) |
. | 点 |
! | 感叹号 |
| | 管道(另请参阅 在表中转义管道) |
许多 Markdown 应用程序允许您在 Markdown 格式的文本中使用 HTML 标签。如果您更喜欢某些 HTML 标记而不是 Markdown 语法,这将非常有用。例如,有些人发现对图片使用 HTML 标签更容易。当您需要更改元素的属性时,例如指定文本的颜色或更改图片的宽度,使用 HTML 也很有帮助。
要使用 HTML,请将标签放在 Markdown 格式文件的文本中。
This **word** is bold. This <em>word</em> is italic.
渲染的输出如下所示:
这个词很粗。这个词是斜体的。
出于安全原因,并非所有 Markdown 应用程序都支持 Markdown 文档中的 HTML。如有疑问,请查看 Markdown 应用程序的文档。某些应用程序仅支持 HTML 标记的子集。
使用空行将块级 HTML 元素(如 、 、 和 )与周围内容分开。尽量不要用制表符或空格缩进标签 — 这可能会干扰格式设置。<div>
<table>
<pre>
<p>
您不能在块级 HTML 标记中使用 Markdown 语法。例如,不起作用。<p>italic and **bold**</p>
在 60 页中学习 Markdown。《Markdown 指南》专为新手和专家设计,是一本全面的参考书,包含您入门和掌握 Markdown 语法所需的一切。
获取书籍