Skip to content

Markdown 基础语法

标题

markdown 支持6级标题,基本形式为 # headline,注意,# 后需要有一个空格

标题大小 对应语法
level 1 # head
level 2 ## head
level 3 ### head
level 4 #### head
level 5 ###### head
level 6 ###### head

段落

在markdown中,你需要使用一行或多行空白行将段落分隔开;注意,简单的换行在显示时并不会产生段落分隔的效果

this is paragraph1, you can type something here...

this is paragraph2, you can type something here...

this is paragraph3, you can type something here...

粗体

使用 **text** 的形式可以加粗字体

语法 效果
**text** text

斜体

使用 *text* 的形式可以斜体显示字体

语法 效果
*text* text
***text*** 粗体加斜体

删除线

使用 ~~text~~ 的形式可以产生删除线效果

语法 效果
~~text~~ text

引用

使用 > text 可以创建一个引用块;例如

> this is a paragraph
渲染效果如下

this is a paragraph

markdown 还支持多级引用;例如

> this is a paragraph1
>> this is a paragraph2
>>> this is a paragraph3
渲染效果如下

this is a paragraph

this is a paragraph2

this is a paragraph3

无序列表

使用 -*+ 都可以创建无序列表;注意,符号后有一个空格;例如

- C++
- Java
- Javascript

渲染效果如下:

  • C++
  • Java
  • Javascript

缩进一个或多个列表项可创建嵌套列表;例如

- C++
    - text1
    - text2
- Java
- Javascript

渲染效果如下:

  • C++
    • text1
    • text2
  • Java
  • Javascript

有序列表

使用 1. 2. 3. 即可创建有序列表;注意,符号后有一个空格;例如

1. C++
2. Java
3. Javascript

渲染效果如下:

  1. C++
  2. Java
  3. Javascript

缩进一个或多个列表项可创建嵌套列表;例如

1. C++
    1. text1
    2. text2
2. Java
3. Javascript

渲染效果如下:

  1. C++
    1. text1
    2. text2
  2. Java
  3. Javascript

代码块

行内代码块

使用 `inline code` 既可以创建行内代码块,效果:inline code;如果你要表示为代码的单词或短语中包含一个或多个反引号`,则可以使用双反引号 `` code ``

独立代码块

使用以下形式可以创建独立的代码块

``` language

code block

```

例如

``` python

print("hello world")

```

渲染效果如下

print("hello world")

常见语言对应markdown缩写

语言名称 markdown缩写 语言名称 markdown缩写
C c C# csharp
C++ cpp css css
cuda cuda Go go
HTML html Java java
JavaScript js Julia julia
MATLAB matlab Python py
shell sh TeX tex

分割线

使用三个或以上的 *, -, _ 可以达到分割线的效果;注意,分割线前后需要添加空白行;例如

--------------

渲染效果:


链接

链接的语法:[name](link),例如我们想显示markdown官方教程的链接,可以:

[markdown官方教程](https://markdown.com.cn/basic-syntax/links.html)

渲染效果如下:

markdown官方教程

给链接加悬停文字

如果你想当鼠标悬停在链接上时会出现文字,可以使用以下语法

[markdown官方教程](https://markdown.com.cn/basic-syntax/links.html "this is a name")

渲染效果如下:

markdown官方教程

纯链接

如果单纯想展示没有名字的网址,可以使用以下语法

<https://github.com/RadiumStar>

渲染效果如下:

https://github.com/RadiumStar

图片

如果你想插入图片,可以使用以下语法

![image name](image link)

例如

![photo](assets/images/md_insert_photo.jpg)

渲染效果如下

photo

链接图片

如果你想给图片添加链接,则可以嵌套链接的语法:

[![image name](image link)](web link)

例如

[![photo](assets/images/md_insert_photo.jpg)](https://github.com/RadiumStar)

渲染效果如下

photo

通过 html 实现更复杂的图片操作

markdown 自带的图片插入语法较为简单,如果你想实现更为复杂的功能,可以通过在md文档中书写 html <img> 标签 实现;语法如下:

<img src="image.png" alt="name" width="10" height="10" align="right">

详细的语法参见 mozilla.org: HTML Element img

转义字符

输入转义字符可以让我们展示原本用于格式化 Markdown 文档的字符,只需要在这类字符前加 \

可转义字符如下:

\ ` * _ { } [ ] ( ) # + - . ! |