日常笔记----Markdown教程

Markdown教程

Markdown是一种轻量级标记语言,可用于向纯文本文档添加格式化元素。不需要像word这样的应用程序一样,需要通过单击菜单按钮来格式化单词和短语,我们可以在文本中直接添加Markdown语法实现。

使用Markdown的优势

  • Markdown可以用于很多场合,人们可以用它创建网页,文档,笔记,书籍,演示文稿,电子邮件和技术文档。
  • Markdown是非常便捷的,包含标记格式文本的文件几乎可以在任何应用程序中打开,如果你不喜欢当前使用的Markdown应用程序,可以将文件迁移到另外一个程序中。这与传统的word等文字处理应用形成鲜明的对比,后者将你的文件锁定在专用的文件格式中。
  • Markdown是独立于平台的,你可以在任何设备或者任何系统中创建Markdown格式的文件。
  • Markdown是面向未来的。即使你正在使用的应用程序在未来的某个时间停用了,你还是能够使用其他文本编辑程序阅读你的Markdown格式的文件,这对需要永久保存的文献是一个重大的益处。

Markdown 基本语法

标题

要创建一个标题,需要在单词或短语前面增加符号,使用的符号的数量需要与标题大小级别匹配,共1~6种级别,以下是示例:


示例:

# Heading level 1

## Heading level 2

### Heading level 3

#### Heading level 4

##### Heading level 5

###### Heading level 6

效果:

Heading level 1

Heading level 2

Heading level 3

Heading level 4
Heading level 5
Heading level 6

除了以上方法,在文本下面增加一定数量的==可以创建level 1标题, 增加一定数量的–可以创建level 2标题:


示例:

Heading level 1
================
Heading level 2
-----------------

效果:

Heading level 1

Heading level 2


Note:

  1. 在符号#和标题之间必须增加一个空格。
  2. 在标题行的前后都需要放置空行。

段落换行

换行方式有很多种:
1.需使用空行来分隔不同的行。

 我太喜欢使用Markdown了。

 从现在开始,我要使用Markdown来写我的所有笔记。

2.在行的结尾增加两个空格, 然后键Enter

 我不太喜欢你的东西。   
 从现在开始,我要使用Markdown来写我的所有笔记。

3.如果需要在行中换行,可以输入

<br>

字体

粗体

若要加粗文本,请在单词或短语前后添加两个星号或下划线。要在单词中间加粗以示强调,可以在字母周围加两个星号,不加空格。

示例:

I love **bold text**.
I love __bold text__.
I**O**ve.

效果:
I love bold text.
I love bold text.
IOve.

斜体

要使文本斜体,请在单词或短语前后添加一个星号或下划线。要将单词中间的斜体表示强调,可以在字母周围加一个星号,不加空格。
示例:

I love *Italic text*.
I love _Italic text_.
I*O*ve.

效果:
I love Italic text.
I love Italic text.
IOve.

粗体和斜体

如果需要同时使用粗体和斜体来强调文本,可以在单词或短语的前后分别添加三个星号或下划线。要在单词中间加粗和斜体来强调,可以在字母周围加三个星号,不加空格。

示例:

I am a ***HW engineer***.
I am a ___HW engineer___.
I am a **_HW engineer_**.
HW en***g***ineer

效果:
I am a HW engineer.
I am a HW engineer.
I am a HW engineer.
HW engineer

但是Markdown不支持在单词中间使用下划线表示强调,如下语法是不正确的:

示例:

HW en___g___ineer

效果:
HW en___g___ineer

区块

区块引用

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

示例:

> No news is good news.

效果:

No news is good news.

多段落区块引用

区块引用可能包含多个段落,在段落间之间空白行增加 >。

示例:

> No news is good news.
> 
> Believe not all that you see nor half what you hear.

效果:

No news is good news.

Believe not all that you see nor half what you hear.

区块嵌套引用

区块可以被嵌套,在你需要嵌套的段落前面增加一个 >>。

示例:

> No news is good news.
> 
>> Believe not all that you see nor half what you hear.

效果:

No news is good news.

Believe not all that you see nor half what you hear.

区块中引入其他语法元素

区块中可以包含其他格式语法,但是并不是所有的都能够使用
如下是其中一种嵌入列表的示例:

示例:

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

列表

有序列表

若要创建有序列表,请添加带有数字后跟句号的行项。这些数字不必按数字顺序排列,但列表应该从数字1开始。

示例1:

1. 1st point
2. 2nd point
3. 3rd point
4. 4th point

效果:

  1. 1st point
  2. 2nd point
  3. 3rd point
  4. 4th point

示例2:

1. 1st point
1. 2nd point
1. 3rd point
1. 4th point

效果:

  1. 1st point
  2. 2nd point
  3. 3rd point
  4. 4th point

示例3:

1. 1st point
2. 2nd point
3. 3rd point
   1. before
   2. after
4. 4th point

效果:

  1. 1st point
  2. 2nd point
  3. 3rd point
    1. before
    2. after
  4. 4th point
无序列表

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

示例1:

- 1st point
- 2nd point
- 3rd point
- 4th point

效果:

  • 1st point
  • 2nd point
  • 3rd point
  • 4th point

示例2:

* 1st point
* 2nd point
* 3rd point
* 4th point

效果:

  • 1st point
  • 2nd point
  • 3rd point
  • 4th point

示例3:

+ 1st point
+ 2nd point
+ 3rd point
+ 4th point

效果:

  • 1st point
  • 2nd point
  • 3rd point
  • 4th point

示例4:

- 1st point
- 2nd point
- 3rd point
     - before
     - after
- 4th point

效果:

  • 1st point
  • 2nd point
  • 3rd point
    • before
    • after
  • 4th point

如果需要以数字后跟句点开始无序列表项,则可以使用反斜杠()。

示例:

- 2023\. is a new year for Human.

效果:

  • 2023. is a new year for Human.

若要在列表中添加另一个语法元素,同时保持列表的连续性,请将元素缩进四个空格或一个Tab符,如下面的示例所示:

示例:

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

效果:

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

代码

若要将单词或短语表示为代码,请将其括在反号(`)中。

示例:

Please type `blank` here.

效果:
Please type blank here.

如果要表示为代码的单词或短语包含一个或多个反引号,则可以通过将单词或短语用双反引号(``)括起来进行转义。

示例:

``Use `code` in your Markdown file.``

效果:
Use `code` in your Markdown file.

代码块:若要创建代码块,请将代码块的每行缩进至少四个空格或一个制表符。

示例:

<html>
      <head>
      </head>
    </html>

效果:

分割线

当需要创建一条水平规则时,可以在一行中使用三个或三个以上的星号(***)、破折号(—)或下划线(___)。

示例:

***

---

____________

效果:




链接

普通链接

若要创建链接,请将链接文本括在括号中(例如,[dillinger]),然后立即在括号中加入URL(例如,(https://dillinger.io))。

示例:

My favorite online Markdown editor is [dillinger](https://dillinger.io).

效果:

My favorite online Markdown editor is dillinger.

你也可以选择为链接添加标题。当用户将鼠标悬停在链接上时,它将作为工具提示出现。要添加标题,请在URL后面用引号括起来。

示例:

My favorite online Markdown editor is [dillinger](https://dillinger.io "The best Online Markdown editor").

效果:
My favorite online Markdown editor is dillinger.

另外,还可以用尖括号(<>)将URL或者邮箱地址转为链接。

示例:

<https://dillinger.io>
<xxx@gmail.com>

效果:
https://dillinger.io
xxx@gmail.com

若要强调链接,请在括号和圆括号前后添加星号。要将链接表示为代码,请在括号中添加反号。

示例:

My favorite online Markdown editor is **[dillinger](https://dillinger.io)**.
Please type [`code`](#code) here

效果:
My favorite online Markdown editor is dillinger.
Please type code here

引用样式链接

引用样式的链接是一种特殊的链接,它使URL在Markdown中更容易显示和阅读。引用样式的链接分为两部分:与文本内嵌的部分和存储在文件中的其他地方以使文本易于阅读的部分。

引用样式链接分为两部分,第一部分用两组括号格式化。第一组括号包围了应该显示链接的文本。第二组括号显示一个标签,用于指向存储在文档中其他位置的链接。

第二部分使用以下属性进行格式化:

  1. 标签,在括号中,紧跟着一个冒号和至少一个空格(例如,[label]:)。
  2. 链接的URL,您可以选择将其括在尖括号中。
  3. 链接的可选标题,可以用双引号、单引号或圆括号括起来。
  4. 链接可以放在文本的任意位置

Note: 为了兼容性,一下两点需要注意:
1. 需要用%20对任何空格进行URL编码。
2. 尝试用%28对左括号(()进行URL编码,用%29对右括号()进行URL编码。

示例:

<https://www.example.com/my%20great%20page>
<https://www.example.com/my%20great%20page%28(xxx)%29>

效果:
https://www.example.com/my great page
https://www.example.com/my great page((xxx))

图片

若要添加图像,请添加感叹号(!),后跟括号中的所有文本,并在括号中添加图像资源的路径或URL。您可以选择在路径或URL后面添加一个带引号的标题。

示例:

![The tower is beautiful!](https://lmg.jj20.com/up/allimg/tp09/210H51R3313N3-0-lp.jpg "beautiful tower")

效果:
没有图床,CSDN暂无法显示效果;
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WD2U62VK-1683464839027)(https://lmg.jj20.com/up/allimg/tp09/210H51R3313N3-0-lp.jpg “beautiful tower”)]

若要添加到图像的链接,请将图像的Markdown括在括号中,然后将链接添加到括号中。

示例:

[![The tower is beautiful!](https://lmg.jj20.com/up/allimg/tp09/210H51R3313N3-0-lp.jpg "beautiful tower")](https://lmg.jj20.com/up/allimg/tp09/210H51R3313N3-0-lp.jpg)

效果:
没有图床,CSDN暂无法显示效果;
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ilbL0ZaW-1683464839028)(https://lmg.jj20.com/up/allimg/tp09/210H51R3313N3-0-lp.jpg “beautiful tower”)]

字符显示

若要显示原本用于格式化Markdown文档中的文本的文字字符,请在字符前面添加反斜杠。

示例:

\* Without the backslash, this would be a bullet in an unordered list.

效果:
* Without the backslash, this would be a bullet in an unordered list.

你可以使用反斜杠(),显示如下字符:
\ ` * _ [] {} <> () # + - . ! |

HTML

许多Markdown应用程序允许在Markdown格式的文本中使用HTML标记。有些人发现对图像使用HTML标记更容易。当需要更改元素的属性时,例如指定文本的颜色或更改图像的宽度,使用HTML也很有帮助。

若要使用HTML,请将标记放置在markdown格式文件的文本中:

示例:

This **word** is bold. This <em>word</em> is italic.

效果:
This word is bold. This word is italic.

Note:

1. 使用空行将块级HTML元素(如<div>、<table>、<pre>和<p>)与周围内容分开。尽量不要用Tab符或空格缩进标签,这样会影响格式。
2. 不能在块级HTML标记中使用Markdown语法。例如,<p>斜体和**粗体**</p>。

Markdown 扩展语法

并非所有Markdown应用程序都支持扩展语法元素。需要检查应用程序使用的轻量级标记语言是否支持想要使用的扩展语法元素。

表格

若要添加表格,需使用三个或更多连字符(—)创建每个列的标题,并使用符号(|)分隔每个列。为了保持兼容性,还应该在行两端添加符号(|)。

示例:

|  Syntax   | Description |
| --------- | ----------- |
| Header    | Title       |
| Paragraph | Text        |

效果:

SyntaxDescription
HeaderTitle
ParagraphText

小贴士: Markdown Tables Generator可用于快速生成表格。

对齐

通过在标题行中连字符( - )的左、右或两侧添加冒号( : ),可以将列中的文本向左、向右或向中心对齐。

示例:

| Syntax    | Description |   Test Text |
| :-------- | :---------: | ----------: |
| Header    |    Title    | Here's this |
| Paragraph |    Text     |    And more |

效果:

SyntaxDescriptionTest Text
HeaderTitleHere’s this
ParagraphTextAnd more

隔离代码块

前面我们说过,可以通过通过将行缩进四个空格或一个Tab符来创建代码块。还有一种更方便的方法,你可以在代码块前后行上使用三个反号(```)或三个波浪号(~~~)来实现。

示例:

{
“firstName”: “Colin”,
“lastName”: “Cheng”,
“age”: 30
}

效果:

{
  "firstName": "Colin",
  "lastName": "Cheng",
  "age": 30
}

语法高亮显示

若要添加语法高亮显示,请在隔离代码块前的反号(```)或者波浪号(~~~)旁边指定一种语言。

示例:

~~~json
{
  "firstName": "Colin",
  "lastName": "Cheng",
  "age": 30
}
效果:
~~~json
{
  "firstName": "Colin",
  "lastName": "Cheng",
  "age": 30
}

脚注

若要创建脚注引用,请在括号(1)内添加插入符号和标识符。标识符可以是数字或单词,但不能包含空格或制表符。标识符仅将脚注引用与脚注本身关联起来——在输出中,脚注按顺序编号。

使用另一个插入符号添加脚注,并在括号内加上冒号和文本(1:My footnote.)。你不必在文件的末尾加上脚注。除了列表、块引号和表等其他元素之外,它们可以放在任何地方。

示例:

Dillinger[^1] is one of the best online Markdown editors, and typora[^2] is one of the best offline Markdown editors.

[^1]: https://dillinger.io.
[^2]: https://typora.io/.

效果:
Dillinger1 is one of the best online Markdown editors, and typora2 is one of the best offline Markdown editors.

标题ID

通过创建带有数字符号(#)和自定义标题ID的标准链接,可以链接到文件中带有自定义ID的标题。


Markdown语法:

示例:

[custom IDs](#custom-ids)
|
|
|

<h3 id="custom-ids">My Great Heading</h3>

效果:
custom IDs
|
|
|

My Great Heading


HTML语法:
示例

<a href="#heading-ids">Heading IDs</a>
|
|
|
<h3 id="heading-ids">My Great Heading</h3>

效果:
Heading IDs
|
|
|

My Great Heading


定义列表

若要创建定义列表,请在第一行键入术语。在下一行中,键入一个冒号,后跟一个空格和定义。

示例:

First Term
: This is my first blog.

效果:
First Term
: This is my first blog.

删除线

可以在字的中间划一条水平线,把字划掉。此功能允许你指出某些单词是错误的,不应该包含在文档中。要划掉单词,需要在单词前后使用两个波浪符号(~~)。

示例:

~~The world is flat.~~ We now know that the world is round.

效果:
The world is flat. We now know that the world is round.

任务列表

任务列表允许你创建带有复选框的项目列表。在支持任务列表的Markdown应用程序中,复选框将显示在内容旁边。创建任务列表时,需要在任务列表项前添加破折号(-)和方括号([])。若要选中复选框,请在方括号([x])之间添加x。

示例:

- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media

效果:

  • Write the press release
  • Update the website
  • Contact the media

表情符号

有两种方法可以添加表情到Markdown文本中:复制并粘贴表情符号到你的markdown格式的文本,或键入表情符号代码。

示例:

You are so funny! :joy:

效果:

You are so funny! 😂

Note: 你可以使用从如下URL:https://gist.github.com/rxaviers/7360908 找到常用的表情符号代码表。

高亮

一些Markdown编译器支持高亮文本。若需要高亮文本,在文本前后使用两个等号(==)。

示例:

I need to highlight these ==very important words==.

效果:
本人的application不支持两个等号(==)高亮文本,无法显示效果图。

此外,如果你的application支持HTML,可以使用mark标记:
示例:

I need to highlight these <mark>very important words</mark>.

效果:
I need to highlight these very important words.

下标

一些Markdown编译器允许你使用下标将一个或多个字符定位在以下。若要创建下标,在字符前后各使用一个波浪符号(~)。

示例:

R~2~

效果:
R2

如果你的application支持HTML,可以使用sub标记:

示例:

R<sub>2<sub>

效果:
R2

上标

一些Markdown编译器允许你使用上标将一个或多个字符放在行以上。若要创建上标,在字符前后各使用一个符号(^)。
示例:

P=I^2^R

效果:

P=I2R

如果你的application支持HTML,可以使用sup标记:
示例:

P=I<sup>2</sup>R

效果:
P=I2R

自动URL衔接

Markdown支持自动将URL转为链接:

示例:

http://www.example.com

效果:
http://www.example.com

但是如果不想将URL转为链接,你可以通过将URL表示为带有反引号(`)的代码来删除链接:

示例:
http://www.example.com

效果:
http://www.example.com


  1. https://dillinger.io. ↩︎ ↩︎ ↩︎

  2. https://typora.io/. ↩︎

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值