折腾 Markdown (1)

折腾 Markdown (1)

前言

这个系列收录了 Markdown 的各种写法,也用于定下一些编写规则,督促自己好好写东西。章节安排如下:
第1、2节介绍官方教程里的基本语法;
第3节整理出不同类型文章的不同结构设计;

...更新中...

1 折腾 Markdown 之标题效果

示例:

标题1号

语法:

1
# Heading level 1 

示例:

标题2号

语法:

1
## Heading level 2 

示例:

标题3号

语法:

1
### Heading level 3

示例:

标题4号

语法:

1
#### Heading level 4

示例:

标题5号

语法:

1
##### Heading level 5

示例:

标题6号

语法:

1
###### Heading level 6

注:#和文本中间留有一个空格,这是标准写法,不加空格的话部分解读器无法识别。


2 折腾 Markdown 之段落效果

文本直接编辑就好,没有符号加成。

I really like using Markdown. I think I’ll use it to format all of my documents from now on.

注:直接开始写内容,不要用空格和制表符缩进段落。编辑文段一个换行无效(虽然编辑中看上去到下一行了,但显示还是连起来的),写多个换行只体现一个换行效果。


3 折腾 Markdown 之换行效果

上一节提到段落如何换行,这节展示规范写法,即:
在一行的末尾添加两个或多个空格(视作两个),然后按回车键换行。

This is the first line.
And this is the second line.

注:几乎每个 Markdown 应用程序都支持两个或多个空格进行换行,称为 结尾空格(trailing whitespace) 的方式,但这是有争议的,因为很难在编辑器中直接看到空格,并且很多人在每个句子后面都会有意或无意地添加两个空格。由于这个原因,你可能要使用除结尾空格以外的其它方式来换行。幸运的是,几乎每个 Markdown 应用程序都支持另一种换行方式:HTML 的<br>标签。

为了兼容性,请在行尾添加“结尾空格”或 HTML 的<br>标签来实现换行。


4 折腾 Markdown 之强调效果

4.1 粗体

示例:I just love bold text.
语法:I just love **bold text**.

示例:I just love bold text.
语法:I just love __bold text__.

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

4.2 斜体

示例:Italicized text is the cat’s meow.
语法:Italicized text is the *cat's meow*.

示例:Italicized text is the cat’s meow.
语法:Italicized text is the _cat's meow_.

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

4.3 粗体+斜体

示例:This text is really important.
语法:This text is ***really important***.

或:___really___ / __*really*__ / **_really_** / ***really***

注:Markdown 应用程序在处理单词或短语中间添加的下划线上并不一致。为了实现兼容性,请使用星号将单词或短语的中间部分加粗并以斜体显示,以示重要。


5 折腾 Markdown 之引用效果

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

示例:

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

语法:

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

语法:

1
2
3
> 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.

语法:

1
2
3
> 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.

语法:

1
2
3
4
5
6
> #### The quarterly results look great!
>
> - Revenue was off the chart.
> - Profits were higher than ever.
>
> *Everything* is going according to **plan**.

6 折腾 Markdown 之列表效果

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

6.1 有序列表

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

示例:

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

语法:

1
2
3
4
5
// 数字不必按顺序
1. First item
8. Second item
3. Third item
5. Fourth item

示例:

  1. First item
  2. Second item
  3. Third item
    1. Indented item
    2. Indented item
  4. Fourth item

语法:

1
2
3
4
5
6
7
// 区分列表级
1. First item
2. Second item
3. Third item
1. Indented item
2. Indented item
4. Fourth item

注:缩进3个空格即可。CommonMark和其他一些轻量级标记语言允许使用括号)作为分隔符,例如,1) First item,但并非所有 Markdown 应用程序都支持这种分隔符,因此从兼容性角度来看,这不是一个很好的选择。为了兼容性,使用1. First item

6.2 无序列表

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

示例:

  • First item
  • Second item
  • Third item
  • Fourth item

语法:

1
2
3
4
- First item // 可替换为 * / +
- Second item
- Third item
- Fourth item

示例:

  • First item
  • Second item
  • Third item
    • Indented item
    • Indented item
  • Fourth item

语法:

1
2
3
4
5
6
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item

注: Markdown 应用程序在如何处理同一列表中的不同分隔符方面并不一致。为了保证兼容性,请不要在同一个列表中混合和匹配分隔符,请选择一种分隔符并坚持使用。

6.3 在列表中嵌套其他元素

要在保留列表连续性的同时在列表中添加另一种元素,请将该元素缩进四个空格或一个制表符,如下例所示:

6.3.1 段落

示例:

  • This is the first list item.

  • Here’s the second list item.

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

  • And here’s the third list item.

语法:

1
2
3
4
5
6
*   This is the first list item.
* Here's the second list item.

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

* And here's the third list item.

6.3.2 引用块

示例:

  • This is the first list item.

  • Here’s the second list item.

    A blockquote would look great below the second list item.

  • And here’s the third list item.

语法:

1
2
3
4
5
6
*   This is the first list item.
* Here's the second list item.

> A blockquote would look great below the second list item.

* And here's the third list item.

6.3.3 代码块

代码块通常采用四个空格或一个制表符缩进。当它们被放在列表中时,请将它们缩进八个空格或两个制表符。
示例:

  1. Open the file.

  2. Find the following code block on line 21:

    <html>
      <head>
        <title>Test</title>
      </head>
  3. Update the title to match the name of your website.

语法:

1
2
3
4
5
6
7
8
9
1.  Open the file.
2. Find the following code block on line 21:

<html>
<head>
<title>Test</title>
</head>

3. Update the title to match the name of your website.

6.3.4 图片

  1. Open the file containing the Linux mascot.

  2. Marvel at its beauty.

    一个简单的jpeg

  3. Close the file.

语法:

1
2
3
4
5
6
1.  Open the file containing the Linux mascot.
2. Marvel at its beauty.

![一个简单的jpeg](https://th.bing.com/th?id=ODL.b73bd5175a57713a5f4c311eb3e82d7b&w=298&h=198&c=10&rs=1&qlt=99&bgcl=fffffe&r=0&o=6&pid=WrapstarImage)

3. Close the file.

6.3.5 列表

有序列表中可以嵌套无序列表

  1. First item
  2. Second item
  3. Third item
    • Indented item
    • Indented item
  4. Fourth item

语法:

1
2
3
4
5
6
1. First item
2. Second item
3. Third item
- Indented item
- Indented item
4. Fourth item