Markdown 语法

Markdown 是一种轻量级标记语言,因简洁、高效、易读、易写被大量使用,如 Github、Wikipedia、简书等。

本文主要参考:Markdown 教程

Markdown 标题语法

在标题前面添加#可以创建标题,#的数量代表标题的级别,一共有六级标题。

# 一级标题
## 二级标题
### 三级标题
#### 四级标题
##### 五级标题
###### 六级标题

注意#和标题之间有一个空格。

Markdown 段落语法

要创建段落,要用空白行将一行或多行文本进行分隔。

I really like using Markdown.

I think I'll use it to format all of my documents from now on.

I really like using Markdown.

I think I’ll use it to format all of my documents from now on.

注意不要用空格(Spaces)或制表符(Tabs)缩进段落。

Markdown 换行语法

在一行的末尾添加两个或多个空格 ,然后按回车键,即可创建一个换行。

This is the first line.  
And this is the second line.

This is the first line.
And this is the second line.

Markdown 强调语法

通过将文本设置为粗体或斜体来强调其重要性。

粗体(Bold)

在要加粗的文本前后添加两个星号**或下划线__

I just love **bold text**.
I just love __bold text__.

I just love bold text.
I just love bold text.

若要加粗一个字符串中间的几个字符,则在要加粗部分的两侧各添加两个星号**

Love**is**bold

Loveisbold

建议只使用星号**

斜体(Italic)

在要倾斜的文本前后添加一个星号*或下划线_

Italicized text is the *cat's meow*.
Italicized text is the _cat's meow_.

Italicized text is the cat’s meow.
Italicized text is the cat’s meow.

若要加粗一个字符串中间的几个字符,则在要倾斜部分的两侧各添加一个星号*

A*cat*meow

Acatmeow

建议只使用星号*

粗体(Bold)和斜体(Italic)

要同时用粗体和斜体突出显示文本,请在前后各添加三个星号或下划线。

This text is ***really important***.
This text is ___really important___.
This text is __*really important*__.
This text is **_really important_**.

This text is really important.
This text is really important.
This text is really important.
This text is really important.

要加粗并用斜体显示一个字符串的中间部分,请在要突出显示的部分前后各添加三个星号,中间不要带空格。

This is really***very***important text.

This is reallyveryimportant text.

建议只使用星号***

Markdown 引用语法

在段落前加一个>符号可创建块引用。

> Dorothy followed her through many of the beautiful rooms in her castle.

Dorothy followed her through many of the beautiful rooms in her castle.

多个段落的块引用

块引用可以包含多个段落。在段落之间的空白行添加一个>符号。

> 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.

嵌套块引用

块引用可以嵌套。在要嵌套的段落前添加两个>>符号。

> 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**.

The quarterly results look great!

  • Revenue was off the chart.
  • Profits were higher than ever.

Everything is going according to plan.

Markdown 列表语法

可以将多个条目组织成有序或无序列表。

有序列表

在每个列表项前添加数字并紧跟一个英文句点。以数字1开头但不必按数学顺序排列。

按顺序

1. First item
2. Second item
3. Third item
4. Fourth item
  1. First item
  2. Second item
  3. Third item
  4. Fourth item

不按顺序

1. First item
1. Second item
9. Third item
6. Fourth item
  1. First item
  2. Second item
  3. Third item
  4. Fourth item

嵌套

1. First item
2. Second item
3. Third item
    1. Indented item
    2. Indented item
4. Fourth item

效果如下:

  1. First item
  2. Second item
  3. Third item
    1. Indented item
    2. Indented item
  4. Fourth item

无序列表

在每个列表项前添加-*+可创建无序列表,缩进列表项可创建嵌套列表。

- First item
- Second item
- Third item
- Fourth item
  • First item
  • Second item
  • Third item
  • Fourth item

* First item
* Second item
* Third item
* Fourth item
  • First item
  • Second item
  • Third item
  • Fourth item

+ First item
+ Second item
+ Third item
+ Fourth item
  • First item
  • Second item
  • Third item
  • Fourth item

嵌套

- First item
- Second item
- Third item
    - Indented item
    - Indented item
- Fourth item
  • First item
  • Second item
  • Third item
    • Indented item
    • Indented item
  • Fourth item

在列表中嵌套其他元素

要在保留列表连续性的同时在列表中添加另一种元素,请将该元素缩进四个空格或一个制表符,如下例所示:

段落

*   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.

    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.
  • 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. 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.
  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.

图片

1. Open the file containing the Linux mascot.
2. Marvel at its beauty.

    ![SG, the H2O Bro mascot](https://example.com/SG.jpg)

3. Close the file.
  1. Open the file containing H2O Bro mascot.

  2. Marvel at its beauty.

    SG, the H2O Bro mascot

  3. Close the file.

列表

可以将无序列表嵌套在有序列表中,反之亦然。

1. First item
2. Second item
3. Third item
    - Indented item
    - Indented item
4. Fourth item
  1. First item
  2. Second item
  3. Third item
    • Indented item
    • Indented item
  4. Fourth item

Markdown 代码语法

在单词或短语前后添加反引号`,可将其表示为代码

At the command prompt, type `nano`.

At the command prompt, type nano.

转义反引号

要将表示为代码的单词或短语中包含一个或多个反引号,则可以在其前后添加双反引号``

``Use `code` in your Markdown file.``

Use `code` in your Markdown file.

代码块

要创建代码块,请将代码块的每一行缩进至少四个空格或一个制表符。

<html>
  <head>
  </head>
</html>

Markdown 分隔线语法

要创建分隔线,在单独一行上使用三个或多个星号***、破折号---或下划线___,并且不能包含其他内容。

***

----

_________________



Markdown 链接语法

链接文本放在中括号内,链接地址放在后面的括号中,链接title可选。

超链接Markdown语法代码:[超链接显示名](超链接地址 "超链接Title")

这是一个链接 [RK的空间站](https://rkchen.netlify.app/)。

这是一个链接 RK的空间站

给链接添加Title

链Ttitle是当鼠标悬停在链接上时会出现的文字,这个Title是可选的,它放在圆括号中链接地址后面,跟链接地址之间以空格分隔。

这是一个链接 [RK的空间站](https://rkchen.netlify.app 'RK的空间站')。

这是一个链接 RK的空间站

网址和Email地址

使用尖括号可以很方便地把URL或者email地址变成可点击的链接。
https://rkchen.netlify.app
fake@example.com

https://rkchen.netlify.app
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).

I love supporting the EFF.
This is the Markdown Guide.
See the section on code.

引用型链接

引用样式链接是一种特殊的链接,它使URL在Markdown中更易于显示和阅读。参考样式链接分为两部分:与文本保持内联的部分以及存储在文件中其他位置的部分,以使文本易于阅读。

链接的第一部分格式

引用类型的链接的第一部分使用两组括号进行格式设置。第一组方括号包围应显示为链接的文本。第二组括号显示了一个标签,该标签不区分大小写,可以包含字母,数字,空格或标点符号,用于指向您存储在文档其他位置的链接。若不加第一组括号,则直接显示第二组括号的标签。

[RK的空间站][1]
RK的B站[2]

RK的空间站
RK的B站2

链接的第二部分格式

引用类型链接的第二部分使用以下属性设置格式:

  1. 防在括号中的标签,其后紧跟一个冒号和至少一个空格(例如[label]:

  2. 链接的URL可以选择将其括在尖括号中。

  3. 链接的可选标题,可将其括在双引号,单引号或括号中。

    [1]: https://rkchen.netlify.app (RK的空间站)
    [2]: <https://space.bilibili.com/8515997> 'RK的B站'
    

可以将链接的第二部分放在Markdown文档中的任何位置。有些人将它们放在出现的段落之后,有些人则将它们放在文档的末尾(例如尾注或脚注)。

链接注意事项

不同的 Markdown 应用程序处理URL中间的空格方式不一样。为了兼容性,请尽量使用%20代替空格。

[link](https://www.example.com/my%20great%20page)

Markdown 图片语法

要添加图像,使用感叹号!, 然后在方括号增加替代文本,图片链接放在圆括号里,括号里的链接后可以增加一个可选的图片标题文本。

插入图片Markdown语法代码:![图片alt](图片链接 "图片title")。

![SG](https://example.com/SG.jpg 'H2O Bro')

SG

链接图片

给图片增加链接,请将上述图像的Markdown语句括在方括号中,然后将链接添加在圆括号中。

[![SG](https://example.com/SG.jpg 'H2O Bro')](https://rkchen.netlify.app)

SG

Markdown 转义字符语法

要显示原本用于格式化 Markdown 文档的字符,请在字符前面添加反斜杠字符 \ 。

\* Without the backslash, this would be a bullet in an unordered list.

渲染效果如下:

* Without the backslash, this would be a bullet in an unordered list.

可做转义的字符

以下列出的字符都可以通过使用反斜杠字符从而达到转义目的。

作者

Smaritron

发布于

2025-02-22

更新于

2025-05-15

许可协议