Mobile wallpaper 1Mobile wallpaper 2Mobile wallpaper 3Mobile wallpaper 4Mobile wallpaper 5Mobile wallpaper 6
1289 字
6 分钟
Markdown 教程

Markdown 教程#

这是一个 Markdown 示例,展示了如何编写 Markdown 文件。本文档集成了核心语法和扩展语法 (GFM)。

块级元素#

段落与换行#

段落#

HTML 标签: <p>

一行或多行空白行。(包含虽然只有 spaces(空格)tabs(制表符) 但被视为空白的行。)

代码:

This will be
inline.
This is second paragraph.

预览:


This will be inline. This is second paragraph.


换行#

HTML 标签: <br />

在行尾添加 两个或更多空格

代码:

This will be not
inline.

预览:


This will be not
inline.


标题#

Markdown 支持两种风格的标题:Setext 和 atx。

Setext#

HTML 标签: <h1>, <h2>

使用任意数量的 等号 (=) 代表 <h1>,使用任意数量的 减号 (-) 代表 <h2> 来实现“下划线”效果。

代码:

This is an H1
=============
This is an H2
-------------

预览:


This is an H1#

This is an H2#


atx#

HTML 标签: <h1>, <h2>, <h3>, <h4>, <h5>, <h6>

在行首使用 1-6 个 井号 (#),对应 <h1> - <h6>

代码:

# This is an H1
## This is an H2
###### This is an H6

预览:


This is an H1#

This is an H2#

This is an H6#

或者,你可以“闭合” atx 风格的标题。闭合用的井号数量 不需要匹配 开启标题时的井号数量。

代码:

# This is an H1 #
## This is an H2 ##
### This is an H3 ######

预览:


This is an H1#

This is an H2#

This is an H3#


引用#

HTML 标签: <blockquote>

Markdown 使用邮件风格的 > 字符进行引用。如果你对文本进行硬换行并在每一行前都加上 >,效果最好。

代码:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.

预览:


This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.


Markdown 允许你偷懒,只在硬换行段落的第一行前加上 >

代码:

> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.

预览:


This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.

Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing.


引用可以嵌套(即引用中的引用),只需添加额外层级的 >

代码:

> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.

预览:


This is the first level of quoting.

This is nested blockquote.

Back to the first level.


引用可以包含其他 Markdown 元素,包括标题、列表和代码块。

代码:

> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");

预览:


This is a header.#

  1. This is the first list item.
  2. This is the second list item.

Here’s some example code:

return shell_exec("echo $input | $markdown_script");

列表#

Markdown 支持有序(编号)和无序(项目符号)列表。

无序列表#

HTML 标签: <ul>

无序列表使用 星号 (*)加号 (+)减号 (-)

代码:

* Red
* Green
* Blue

预览:


  • Red
  • Green
  • Blue

等同于:

代码:

+ Red
+ Green
+ Blue

以及:

代码:

- Red
- Green
- Blue

有序列表#

HTML 标签: <ol>

有序列表使用数字后跟英文句点:

代码:

1. Bird
2. McHale
3. Parish

预览:


  1. Bird
  2. McHale
  3. Parish

如果你写成下面这样,可能会意外触发有序列表:

代码:

1986. What a great season.

预览:


  1. What a great season.

你可以使用 反斜杠转义 (\) 句点:

代码:

1986\. What a great season.

预览:


1986. What a great season.


缩进#

列表中的引用#

要在列表项中放入引用,引用的 > 分隔符需要缩进:

代码:

* A list item with a blockquote:
> This is a blockquote
> inside a list item.

预览:


  • A list item with a blockquote:

    This is a blockquote inside a list item.


列表中的代码块#

要在列表项中放入代码块,代码块需要缩进两次 —— 8 个空格两个制表符

代码:

* A list item with a code block:
<code goes here>

预览:


  • A list item with a code block:

嵌套列表#

代码:

* A
* A1
* A2
* B
* C

预览:


  • A
    • A1
    • A2
  • B
  • C

代码块#

HTML 标签: <pre>

将块中的每一行缩进至少 4 个空格1 个制表符

代码:

This is a normal paragraph:
This is a code block.

预览:


This is a normal paragraph:

This is a code block.

代码块会一直持续,直到遇到没有缩进的行(或文章结束)。

在代码块内,符号 (&)尖括号 (< 和 >) 会自动转换为 HTML 实体。

代码:

<div class="footer">
&copy; 2004 Foo Corporation
</div>

预览:


<div class="footer">
&copy; 2004 Foo Corporation
</div>

接下来的“围栏代码块”和“语法高亮”部分是扩展功能,你可以使用另一种方式来编写代码块。

围栏代码块#

只需用 ``` 包裹你的代码(如下所示),就不需要缩进四个空格。

代码:

Here's an example:
```
function test() {
console.log("notice the blank line before this function?");
}
```

预览:


Here’s an example:

Markdown 教程
https://github.com/emn178/markdown
作者
emn178
发布于
2025-01-20
许可协议
Unlicensed

部分信息可能已经过时

封面
Sample Song
Sample Artist
封面
Sample Song
Sample Artist
0:00 / 0:00