1. Markdown Basic Grammar
1. Title syntax
To create a title, precede a word or phrase with a pound sign (#). The number of # represents the level of the title. For example, adding three #s creates a third-level heading (<h3>) (for example: ### My Header).
Markdown syntax | HTML | preview effect |
---|---|---|
# 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 Optional Syntax
You can also add any number of == signs below the text to identify first-level headings, or – signs to identify second-level headings.
Markdown syntax | HTML | preview effect |
---|---|---|
Heading level 1 ============ |
<h1>Heading level 1</h1> | Heading level 1 |
Heading level 2 --------------------- |
<h2>Heading level 2</h2> | Heading level 2 |
1.2 Best Practices
Different Markdown applications handle the space between # and headings inconsistently. For compatibility, separate # and the title with a space.
✅ Do this | ❌ Don’t do this |
---|---|
# Here’s a Heading | #Here’s a Heading |
2. Paragraph Grammar
2.1 Best Practices
3. Newline syntax
3.1 Best Practices
4. Emphasis on Grammar
Emphasize the importance of text by making it bold or italic.
4.1 Bold
To bold text, add two asterisks (asterisks) or underscores (underscores) before and after a word or phrase. To bold the middle of a word or phrase for emphasis, add two asterisks (asterisks) on either side of the bolded part.
Markdown syntax | HTML | preview effect |
---|---|---|
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 Best Practices
Markdown applications are not consistent on how to handle underscores in the middle of words or phrases. For compatibility, use asterisks when bolding the middle of a word or phrase.
✅ Do this | ❌ Don’t do this |
---|---|
Love**is**bold | Love__is__bold |
4.2 Italic
To italicize text, add an asterisk (asterisk) or underscore (underscore) before or after a word or phrase. To italicize the middle of a word, add an asterisk before and after the letter, with no spaces in between.
4.2.1 Best Practices
To highlight text in both bold and italics, add three asterisks or underlines before and after a word or phrase. To bold and italicize the middle of a word or phrase, add three asterisks before and after the part you want to highlight, with no spaces in between.
✅ Do this | ❌ Don’t do this |
---|---|
A*cat*meow | A_cat_meow |
4.3 Bold and Italic
To highlight text in both bold and italics, add three asterisks or underlines before and after a word or phrase. To bold and italicize the middle of a word or phrase, add three asterisks before and after the part you want to highlight, with no spaces in between.
4.3.1 Best Practices
✅ 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 Unordered lists
To create an unordered list, precede each list item with a dash (-), asterisk (*), or plus sign (+). Indenting one or more list items creates nested lists.
Markdown Official Tutorial: https://markdown.com.cn/