zhzhongshi
markdown基础语法

markdown基础语法

Markdown 基础语法

Markdown是一种轻量级标记语言,排版语法简洁,让人们更多地关注内容本身而非排版。它使用易读易写的纯文本格式编写文档,可与HTML混编,可导出 HTML、PDF 以及本身的 .md 格式的文件。因简洁、高效、易读、易写,Markdown被大量使用,如Github、Wikipedia、简书等。

千万不要被“标记”、”语言“ 吓到,Markdown的语法十分简单,常用的标记符号不超过十个,用于日常写作记录绰绰有余,不到半小时就能完全掌握。

就是这十个不到的标记符号,却能让人优雅地沉浸式记录,专注内容而不是纠结排版,达到”心中无尘,码字入神“的境界。

标题

要创建标题,请在单词或短语前面添加井号 (#) 。#的数量代表了标题的级别。例如,添加三个 # 表示创建一个三级标题 (<h3>) (例如:### My Header)。

Markdown语法 HTML 预览效果
# Heading level 1 <h1>Heading level 1</h1>

Heading level 1

## Heading level 2 <h2>Heading level 2</h2>

Heading level 2

### Heading level 3 <h3>Heading level 3</h3>

Heading level 3

#### Heading level 4 <h4>Heading level 4</h4>

Heading level 4

##### Heading level 5 <h5>Heading level 5</h5>
Heading level 5
###### Heading level 6 <h6>Heading level 6</h6>
Heading level 6

段落

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

1
2
3
I really like using Markdown.

I think I'll use it to format all of my documents from now on.
1
2
3
<p>I really like using Markdown.</p>

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

I really like using Markdown.

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

换行

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

1
2
This is the first line.  
And this is the second line.
1
2
This is the first line.<br>
And this is the second line.

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

强调语法

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

粗体(Bold)

要加粗文本,请在单词或短语的前后各添加两个星号(asterisks)或下划线(underscores)。如需加粗一个单词或短语的中间部分用以表示强调的话,请在要加粗部分的两侧各添加两个星号(asterisks)。

1
I just love **bold text**.
1
I just love __bold text__.
1
I just love <strong>bold text</strong>

I just love bold text.

斜体(Italic)

要用斜体显示文本,请在单词或短语前后添加一个星号(asterisk)或下划线(underscore)。要斜体突出单词的中间部分,请在字母前后各添加一个星号,中间不要带空格。

1
Italicized text is the *cat's meow*.
1
Italicized text is the _cat's meow_.
1
Italicized text is the <em>cat's meow</em>

Italicized text is the cat’s meow.

粗体(Bold)和斜体(Italic)

要同时用粗体和斜体突出显示文本,请在单词或短语的前后各添加三个星号或下划线。要加粗并用斜体显示单词或短语的中间部分,请在要突出显示的部分前后各添加三个星号,中间不要带空格。

1
This text is ***really important***.
1
This text is **_really important_**.
1
This text is <strong><em>really important</em></strong>.

This text is really important.

引用

要在文本前面添加引用,请在文本前面添加大于号(>)和空格。

1
> This is a blockquote.

This is a blockquote.

多个段落的块引用

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

1
2
3
> This is the first paragraph in a blockquote.
>
> This is the second paragraph in a blockquote.

This is the first paragraph in a blockquote.

This is the second paragraph in a blockquote.

嵌套块引用

块引用可以嵌套。为嵌套的块引用添加一个 > 符号。

1
2
3
> This is the outer blockquote.
>
> > This is the inner blockquote.

This is the outer blockquote.

This is the inner blockquote.

带有其它元素的块引用

块引用可以包含其他 Markdown 元素,如列表、代码块、图片、链接等。

1
2
3
4
5
> Here's an example of a blockquote with a list:
>
> 1. First item
> 2. Second item
> 3. Third item

Here’s an example of a blockquote with a list:

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

列表

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

有序列表

要创建有序列表,请在条目前面添加数字和句点。数字和句点之间需要有一个空格。

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

无序列表

要创建无序列表,请在条目前面添加一个星号、加号或减号。

1
2
3
- First item
- Second item
- Third item
  • First item
  • Second item
  • Third item

嵌套列表

列表可以嵌套。为嵌套的列表添加四个空格或一个制表符。

1
2
3
4
5
1. First item
- First nested item
- Second nested item
2. Second item
3. Third item
  1. First item
    • First nested item
    • Second nested item
  2. Second item
  3. Third item

在列表中嵌套其他元素

列表可以包含其他 Markdown 元素,如段落、代码块、图片、链接等。

1
2
3
4
5
6
1. First item
- First nested item
- <img src="https://via.placeholder.com/150" alt="placeholder">
- Second nested item
2. Second item
3. Third item
  1. First item
    • First nested item
      • placeholder
    • Second nested item
  2. Second item
  3. Third item

代码块

要在文本中插入代码块,请将代码用反引号(`)包裹起来。

1
<pre><code class="language-python">print("Hello, world!")</code></pre>

Here’s an example of a code block:

1
print("Hello, world!")

链接

要创建链接,请在方括号内输入链接文字,然后在括号内输入链接地址。

1
[GitHub](https://github.com)

GitHub

链接的标题

要为链接添加标题,请在链接后面添加一个空格,然后在括号内输入标题。

1
[GitHub](https://github.com "GitHub homepage")

GitHub

链接的图片

要在链接中插入图片,请在方括号内输入图片描述,然后在括号内输入图片地址。

1
[![GitHub logo](https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png)](https://github.com)

GitHub logo

图片

要插入图片,请在方括号内输入图片描述,然后在括号内输入图片地址。

1
![GitHub logo](https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png)

GitHub logo

图片的标题

要为图片添加标题,请在图片后面添加一个空格,然后在括号内输入标题。

1
![GitHub logo](https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png "GitHub logo")

GitHub logo

表格

要创建表格,请在每一行的开头和结尾使用管道符(|)分隔单元格,并在每一行的开头使用破折号(-)分隔标题行。

1
2
3
4
| Header 1 | Header 2 | Header 3 |
| -------- | -------- | -------- |
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
Header 1 Header 2 Header 3
Cell 1 Cell 2 Cell 3
Cell 4 Cell 5 Cell 6

转义字符

Markdown 使用反斜杠(\)作为转义字符。如果需要在文本中插入反斜杠,请在反斜杠后面添加一个反斜杠。

1
\*This text will be italicized\*

可做转义的字符

  • \ 反斜杠
  • ` 反引号
    • 星号
  • _ 底线
  • {} 花括号
  • [] 方括号
  • () 括号
  • 井号

    • 加号
    • 减号
  • . 句点
  • ! 惊叹号
  • | 管道符
本文作者:zhzhongshi
本文链接:https://zhzhongshi.github.io/2025/03/02/0302/markdown/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可