Markdown基本语法和扩展语法

一、Markdown基本语法

1、标题语法

要创建标题,请在单词或短语前面添加井号 (#) 。# 的数量代表了标题的级别。例如,添加三个 # 表示创建一个三级标题 (<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.1可选语法


还可以在文本下方添加任意数量的 == 号来标识一级标题,或者 – 号来标识二级标题。

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

Heading level 1

Heading level 2
---------------------
<h2>Heading level 2</h2>

Heading level 2

1.2最佳实践


不同的 Markdown 应用程序处理 # 和标题之间的空格方式并不一致。为了兼容考虑,请用一个空格在 # 和标题之间进行分隔。

✅ Do this ❌ Don’t do this
# Here’s a Heading #Here’s a Heading

2、段落语法

在这里插入图片描述

2.1最佳实践


在这里插入图片描述

3、换行语法

在这里插入图片描述

3.1最佳实践


在这里插入图片描述

4、强调语法

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

4.1 粗体(Bold)


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

Markdown语法 HTML 预览效果
I just love **bold text**. I just love <strong>bold text</strong>. I just love bold text.
I just love _bold text_. I just love <strong>bold text</strong>. I just love bold text.
Love**is**bold Love<strong>is</strong>bold Loveisbold

4.1.1 最佳实践

Markdown 应用程序在如何处理单词或短语中间的下划线上并不一致。为兼容考虑,在单词或短语中间部分加粗的话,请使用星号(asterisks)。

✅ Do this ❌ Don’t do this
Love**is**bold Love__is__bold

4.2 斜体(Italic)


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

4.2.1 最佳实践

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

✅ Do this ❌ Don’t do this
A*cat*meow A_cat_meow

4.3 粗体(Bold)和斜体(Italic)


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

4.3.1 最佳实践

✅ Do this ❌ Don’t do this
This is really***very***important text. This is really___very___important text.

5、引用语法

要创建块引用,请在段落前添加一个 > 符号。

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

渲染效果如下所示:

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

5.1 多个段落的块引用


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

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

5.2 嵌套块引用


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

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

5.3 带有其它元素的块引用


块引用可以包含其他 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.

6、列表语法

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

6.1有序列表


要创建有序列表,请在每个列表项前添加数字并紧跟一个英文句点。数字不必按数学顺序排列,但是列表应当以数字 1 起始。
在这里插入图片描述

6.1.1 有序列表最佳实践

CommonMark and a few other lightweight markup languages let you use a parenthesis ()) as a delimiter (e.g., 1) First item), but not all Markdown applications support this, so it isn’t a great option from a compatibility perspective. For compatibility, use periods only.

✅ Do this ❌ Don’t do this
1. First item
2. Second item
1) First item
2) Second item

6.2 无序列表


要创建无序列表,请在每个列表项前面添加破折号 (-)、星号 (*) 或加号 (+) 。缩进一个或多个列表项可创建嵌套列表。
在这里插入图片描述

Markdown 官方教程: https://markdown.com.cn/

猜你喜欢

转载自blog.csdn.net/m0_68705273/article/details/132070069