Markdown基础语法+部分扩语法(vscode)

发布时间 2023-10-29 21:13:12作者: _三五七言

mdk语法

基础语法

标题语法


在标题前添加井号##的数量代表了标题的级别。考虑到不同mkd应用程序的兼容性,在#和标题之间用一个空格进行分隔。

# Heading level 1(<h1>)
## Heading level 2(<h2>)

换行语法


在一行末尾添加两个或多个空格然后按回车键,或者在行末使用<br>(line break)创建一个换行。如:

示例:

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

效果:
This is the first line.
And this is the second line.
And this is the third line.

段落语法


要创建段落,使用空白行将段落之间进行分隔。如:
I really like using Markdown.

I think I`ll use it format all of documents from now on.

强调语法


粗体(Bold)

在要加粗的文字前后各添加两个星号**<strong>text</strong>,实现文字加粗。

示例:

**The bold text.**  
<strong>The bold text.</strong> 

效果:
The bold text.
The bold text.

斜体(Italic)

在要斜体显示的文字前后各添加一个星号*<em>text</em>,实现文字斜体显示。

示例:

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 cat’s meow.

粗体和斜体

在要加粗并斜体显示的文字前后各添加三个星号***或对称的<strong><em>text</em></strong>,实现文字斜体显示。

示例:

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

效果:
This text is really important.
This text is really important.

引用语法


在段落前添加>符号创建块引用。

示例:

> this is a cite.

效果:

this is a cite.

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

示例:

> 我给你你出生多年前的
>
> 一朵黄玫瑰的记忆

效果:

我给你你出生多年前的

一朵黄玫瑰的记忆

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

示例:

> 我给你你出生多年前的
>
>> 一朵黄玫瑰的记忆

效果:

我给你你出生多年前的

一朵黄玫瑰的记忆

块引用可以包含其他Markdown格式的元素,但并非所有元素都可以使用。

示例:

> ###### 我给你你出生多年前的
>
> - 一朵**黄玫瑰**的记忆

效果:

我给你你出生多年前的
  • 一朵黄玫瑰的记忆

列表语法


有序列表

在每个列表前添加紧跟英文句点.的数字。数字不必顺序排列,但应从1起始,缩进一个或多个列表可创建嵌套列表.

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

  1. First item
  2. Second item
    1. First item
    2. Second item

无序列表

在每个列表前添加-,缩进一个或多个列表可创建嵌套列表。

示例:

- First item
- Second item
  - First item
  - Second item
    - First item

效果:

  • First item
  • Second item
    • First item
    • Second item
      • First item

在列表中嵌套其他元素

要在保留列表连续性的同时在列表中添加另一种元素,需将该元素缩进一个制表符。

段落
示例:

- This is the first list item.
- This is the second list item.
    I need to add other paragraph below the second list item.
- This is the third list item.

效果:

  • This is the first list item.
  • This is the second list item.
    I need to add other paragraph below the second list item.
  • This is the third list item.

引用块
示例:

- This is the first list item.
- This is the second list item.
    > I need to add other paragraph below the second list item.
- This is the third list item.

效果:

  • This is the first list item.
  • This is the second list item.

    I need to add other paragraph below the second list item.

  • This is the third list item.

代码块
代码块被放在列表时,使用两个制表符缩进。
示例:

- This is the first list item.
- This is the second list item.
        ```c
        {I need to add other paragraph below the second list item.}
        ```
- This is the third list item.

效果:

  • This is the first list item.
  • This is the second list item.
    c {I need to add other paragraph below the second list item.}
  • This is the third list item.

图片
示例:

- This is the first list item.
- This is the second list item.
    ![这是图片](https://img2023.cnblogs.com/blog/3258107/202310/3258107-20231029211148098-7528025.jpg) "这是章鱼哥") 
- This is the third list item.

效果:

  • This is the first list item.
  • This is the second list item.
    这是图片 "这是章鱼哥")
  • This is the third list item.

列表
示例:

1. This is the first list item.
2. This is the second list item.
    - I need to add other paragraph below the second list item.
3. This is the third list item.

效果:

  1. This is the first list item.
  2. This is the second list item.
    • I need to add other paragraph below the second list item.
  3. This is the third list item.

代码语法


行内代码

将要显示成代码的文字包裹在反引号(`)中,如果文字中包含反引号,可以使用双反引号将其包裹。
示例:

Use `code` in my documents.
``Use `code` in my documents.``

效果:
Use code in my documents.
Use `code` in my documents.

代码块

在代码块前后添加三个反引号```或波浪号~~~。若要使用语法高亮,需在代码块前的三个反引号后指定语言。
示例:

```c
int main()
{
    int i = 0;
    printf("%d\n", i);
    return 0;
}
效果:
```c
int main()
{
    int i = 0;
    printf("%d\n", i);
    return 0;
}

分割线语法


创建分割线,请在单独一行上使用三个破折号---,不能包含其他内容。

链接语法


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

给链接增加title
链接title是当鼠标悬停在链接上时会出现的文字,它放在链接地址后面,跟链接地址之间以空格分隔。

语法:
[超链接显示名]*(超链接地址 "超链接title")

示例:

这是一个链接[Markdown语法](https://markdown.com.cn/basic-syntax/ "官方Markdown语法教程网站")。

效果:
这是一个链接Markdown语法

网址和Email地址

使用尖括号<>可以很方便的将URL和email变成可点击的链接。

示例:

<https://markdown.com.cn/basic-syntax/>
<3568970551@qq.com>

效果:
https://markdown.com.cn/basic-syntax/
3568970551@qq.com

带格式话的链接

强调链接,在链接前后增加相应个数的星号,要将链接显示为代码,需在方括号中添加反引号。

示例:

I love this ***[instructions](https://markdown.com.cn/basic-syntax/)***.
I love this [`instructions`](https://markdown.com.cn/basic-syntax/).

效果:
I love this instructions.
I love this instructions.

引用类型链接

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

链接的第一部分格式
第一部分使用两组方括号。第一组方括号内放置链接显示文本,第二组方括号内放置显示的标签,该标签用于指向存储在文档其他位置的链接。

  • 两组括号中应包含一个空格,第二组括号内的标签区分大小写,可以包好数字、字母、空格或标点符号。

示例:[显示文本] [1]

链接的第二部分格式
第二部分使用以下属性进行格式设置:

  1. 第二组标签及其空格后,紧跟一个冒号和至少一个空格([lable]: );
  2. 链接的URL,将其扩在尖括号中;
  3. 连接的可选标题,将其扩在双引号中
    • title和URL之间不能有空格!
  • 考虑到不同版本Markdown程序的兼容性,URL中间的空格使用%20代替。

  • 可以将链接的第二部分放在文档中的任何位置,比如在文档末尾作为尾注或脚注

[1]: https://markdown.com.cn/basic-syntax/"官方Markdown语法教程链接"

图片语法


普通图片

要添加图像,使用感叹号!,在方括号内添加替代文本,图像的Markdown链接放在圆括号内,连接后可以增加一个可选的title。

  • 使用[插件] [2],复制图片,再粘贴到文档任意位置,即可产生图片链接。

语法:
![图片alt](图片链接 "图片title")

示例:

![这是图片](https://img2023.cnblogs.com/blog/3258107/202310/3258107-20231029211148098-7528025.jpg) "这是章鱼哥") 

效果:
这是图片 "这是章鱼哥")

链接图片

给图片添加链接,将图像的Markdown扩在方括号内,然后将链接扩在圆括号内。

语法:
[![Alt text](Markdown "title")](URL)

示例:

[![这是图片](https://img2023.cnblogs.com/blog/3258107/202310/3258107-20231029211148098-7528025.jpg) "这是章鱼哥") ](https://www.cnblogs.com/poem357/)

效果:
这是图片 "这是章鱼哥")

[2]: https://blog.csdn.net/javahighness/article/details/90454136"Paste Image"

转义字符语法


要显示原本用于格式化Markdown文档的字符,请在字符前添加反斜杠字符\
示例:* 一朵黄玫瑰的记忆。

Markdown内嵌HTML标签


官方教程

扩展语法

表格


要添加表,请使用三个或多个连字符---创建每列的标题,使用管道|分隔每列。通过在标题连字符左侧或右侧添加冒号:使列中的文本左对齐或右对齐。

示例:

|title1|title2|title3|
|:---|:---:|---:|
|`code`|text|**bold**|
||<https://markdown.com.cn/extended-syntax/tables.html>|

效果:

title1 title2 title3
code text bold
https://markdown.com.cn/extended-syntax/tables.html
  • 转义管道字符,需使用HTML字符代码&#124;,使表中显示|

数学公式


  1. 在LaTex语法前后分别插入一个$创建行内公式
  2. 在LaTex语法前后分别插入两个$创建行间公式
  • 推荐插件:MarkdownTools有常用符号,还可以在线设计公式。

常见语法:

符号或结构 语法
$\alpha$ \alpha
$\beta$ \beta
$\chi$ \chi
$\frac{ab}{cd}$ \frac{ab}
$\sqrt{abc}$ \sqrt

脚注


脚注使我们可以添加注释和参考,而不使正文混乱,读者可以单击链接跳至页面底部的脚注内容。

创建脚注参考,需在方括号[^1]内添加符号和标识符。标识符可以是数字或字母,但不能包含空格和制表符。脚注按顺序标号。

在括号内使用另一个插入符号和数字添加脚注,并用冒号和文本([^1]:My footnote.)。脚注可以添加到文档任意位置,列表、块引用和表格等元素除外。

示例:

Here`s a simple footnote[^1], and here is the longer one.[^bignote]

效果:
Here`s a simple footnote[1], and here is the longer one.[2]

标题编号


官方教程网址

定义列表


一些Markdown处理器允许创建术语及其对应定义的定义列表。要创建定义列表,需在第一行上键入术语。在下一行,键入一个冒号,后跟一个空格和定义。

First Term
This is the definition of the first term.
Second Term
This is one definition of the second term.
This is another definition of the second term.

删除线


在删除显示的文本前后添加两个波浪号~~

给你一朵红玫瑰黄玫瑰的记忆

任务列表


创建带复选框的任务列表,需在任务列表前添加破折号-和方括号[],并在两者之间和方括号内添加空格( [ ])。若要选择复选框,需在方括号内添加x([x])。

示例:

- [ ] 在地球上花费不多
- [ ] 梦境不收入场费
- [x] 幻想只有在破灭时才须代价 

效果:

使用emoji表情


  1. 将表情复制粘贴到Markdown格式的文本中
  2. 键入表情符号简码 emoji shortcode
  3. 推荐插件:Markdowntools

示例:

去露营了!:tent:
开心开心!:joy:

效果:
去露营了!⛺
开心开心!?

自动网址链接


许多Markdown处理器会自动将URL转换为链接。这意味着即使输入的网址未使用方括号,Markdown处理器也会自动将其转换为链接。

  • 如果不希望自动链接URL,可以将其变成行内代码的形式。

示例:
https://markdown.com.cn/extended-syntax/automatic-url-linking.html

https://markdown.com.cn/extended-syntax/automatic-url-linking.html

目录


在需要显示目录的地方添加[TOC]即可


  1. This is the first footnote. ↩︎

  2. This is the second footnote. ↩︎