Markdown个人学习笔记

101 阅读7分钟

为什么使用Markdown

Markdown是一种轻量级标记语言,排版语法简洁,让人们更多地关注内容本身而非排版。它使用易读易写的纯文本格式编写文档,可与HTML混编,可导出 HTML、PDF 以及本身的 .md 格式的文件。因简洁、高效、易读、易写,Markdown被大量使用,如Github、Wikipedia、简书等。

Markdown语法

基本语法

1. 标题语法
2. 段落语法
3. 换行语法
4. 强调语法
5. 引用语法
6. 列表语法
7. 代码语法
8. 分割线语法
9. 链接语法
10. 图片语法
11. 转意字符
12. 内嵌HTML标签

进阶语法

1. 表格
2. 代码块
3. 脚注
4. 标题编号
5. 定义列表
6. 删除线
7. 任务列表

标题语法 {#title}

  • 语法: 在内容前面加 (#)。 (#)数量代表了标题等级,等级等价于h标签等级。

# 一级标题   一级标题
            ==
## 二级标题 二级标题
            --
### 三级标题
#### 四级标题
##### 五级标题
###### 六级标题

title.png

段落语法 {#area}

  • 创建段落,使用空白行将一行或者多行隔离
l really like markdown

i think i'll use it to 
formate all my documents from now on.
  • 不要用空格(spaces)或制表符( tabs)缩进段落。

换行语法 {#breakLine}

  • 在一行的末尾添加两个或多个空格,然后按回车键,即可创建一个换行(<br>)。
  • 也可以使用HTML<br>标签。

强调语法 {#emphasize}

  • 使用两个星号或者下划线加粗文本。
i just like **markdown**
i just like __markdown__

i just like markdown

  • 使用一个星号或者下划线显示斜体。
i just like *markdown*
i just like _markdown_

i just like markdown

  • 使用三个星号或者下划线显示斜体并且加粗。
i just like ***markdown***
i just like ___markdown___

i just like markdown

  • 注意: 如果是单词或短语的中间部分需要使用,考虑兼容性,最好使用(*)。

引用语法 {#quote}

  • 使用>符号创建块引用, 引用可以嵌套(>>)。引用内部空白行需要加>,引用内部也可以包含其他markdown元素,包括标题、列表、代码区块等。

The quarterly results look great!

  • Revenue was off the chart.

  • Profits were higher than ever.

Everything is going according to plan.

列表语法 {#table}

  • 有序列表 创建有序列表,在每个列表项前添加数组并紧跟一个英文句号。数字不需要排序,但是初始值为1。
1. first item
8. second item
    1. indented item
    3. indented item
4. third item

效果如下:

  1. first item
  2. second item
    1. indented item
    2. indented item
  3. third item
  • 无序列表同有序列表,前面数字换成破折号(-)、星号(*)或者加号(+)。
+ first item
- second item
    * indented item
    * indented item
+ third item

效果如下:

  • first item
  • second item
    • indented item
    • indented item
  • third item

代码语法 {#code}

  • 使用反引号(`)将单词或者短语转为代码。
  • 如果要转意反引号(`), 可以通过将单词或短语包裹在双反引号(`)中。
``Use `code` in your Markdown file.``

Use `code` in your Markdown file.

分割线语法 {#divisionLine}

  • 单独一行上使用三个或多个星号 (***)、破折号 (---) 或下划线 (___) ,并且不能包含其他内容。
  • 为了兼容性,请在分隔线的前后均添加空白行。
***

---

___


链接语法 {#link}

  • 将链接文本放在中括号中,链接地址放在后面括号中,链接title可选。
这是一个链接 [Markdown语法](https://markdown.com.cn "最好的markdown教程")。

效果如下:

这是一个链接 Markdown语法

  • 使用尖括号可以很方便地把URL或者email地址变成可点击的链接。 <https://markdown.com.cn>

图片语法 {#picture}

  • 与链接语法类似,前面加上感叹号(!)创建一个图片标题文本。 ![图片alt](图片链接 "图片title")
![这是图片](/assets/img/philly-magic-garden.jpg "Magic Gardens")

效果如下:

  • 图片链接地址可为网络地址。

转意字符 {#meanChange}

  • 在字符前面使用\来显示原本要展示的文档字符。 (\ ` * _ {} () # + - . ! |)

  • 特殊字符自动转义。 在html文件中,在 HTML 文件中,有两个字符需要特殊处理: <&< 符号用于起始标签,& 符号则用于标记 HTML 实体,如果你只是想要使用这些符号,你必须要使用实体的形式,像是 &lt;&amp;

内嵌HTML标签 {#innerHtml}

  • 可以直接使用HTML标签本身,不需要额外标注。
  • 可以使用行内标签<span><cite><del><img>等。 块级元素<table><pre><p><div>等。如果使用块级元素,则标签前后需要加入空白行。
This **word** is bold. This <em>word</em> is italic.

<table>
    <tr>
        <td>Foo</td>
        <td>Foo</td>
    </tr>
    <tr>
        <td>Foo</td>
        <td>Foo</td>
    </tr>
</table>

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

Foo Foo
Foo Foo
  • 注意 Markdown 语法在 HTML 区块标签中将不会被进行处理。

拓展语法

表格 {#form}

  • 使用三个或者多个连字符(---)创建列,下划线(|)分割每列。
  • 根据连字符长度来改变每列的宽度。
  • 使用冒号(:)在两侧或者一端,改变对齐方式。
  • 在表格内部可以设置文字格式,包括链接、代码(不是代码块)和强调等。
| Syntax | Description | Size | Text| Algin |
| --- | ----------- | :--- | :---: | -------: |
| *Header* | Title | 10 | header text | [link](https://www.markdown.com.cn "markdown") |
| **Paragraph** | `Text` | 20 | ![imgLink](/assets/img/philly-magic-garden.jpg "Magic Gardens") | right |

效果如下:

SyntaxDescriptionSizeTextAlgin
HeaderTitle10header textlink
ParagraphText20imgLink转存失败,建议直接上传图片文件right

代码块 {#codeArea}

  • 在内容块使用三个反引号(```)创建代码块
  • 在受防护的代码块之前的反引号旁边指定一种语言,可以使语法高亮

codeArea.png

脚注 {#footnote}

  • 脚注使您可以添加注释和参考,而不会使文档正文混乱。 要创建脚注参考,请在方括号([^1])内添加插入符号和标识符。标识符可以是数字或单词,但不能包含空格或制表符。标识符仅将脚注参考与脚注本身相关联-在输出中,脚注按顺序编号。

    在括号内使用另一个插入符号和数字添加脚注,并用冒号和文本([^1]: My footnote.)。您不必在文档末尾添加脚注。您可以将它们放在除列表,块引号和表之类的其他元素之外的任何位置。

  • 参考会在文章最后显示。


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

[^1]: This is the first footnote.

[^bignote]: Here's one with multiple paragraphs and code.

    Indent paragraphs to include them in the footnote.

    `{ my code }`

    Add as many paragraphs as you like.

效果如下: Here's a simple footnote,1 and here's a longer one.2

标题编号 {#titleNumber}

  • 可以在标题上增加自定义ID, 可以使链接直达并使用CSS修改样式。
### My Great Heading {#custom-id}

类似HTML中:

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

效果如下:

My Great Heading {#custom-id}

  • 可以使用链接绑定自定义ID,链接到文件中具有自定义ID的标题。
MarkDownHTML预览效果
[Heading IDs](#heading-ids)<a href="#heading-ids">Heading IDs</a>Heading IDs
  • 其他网站可以通过将自定义标题ID添加到网页的完整URL(例如Heading IDs)来链接到标题。

定义列表 {#defineList}

  • 可以自定义术语及其对应的定义列表。
  • 在第一行定义术语,下一行输入冒号(:),后跟一个空格和定义。
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.

效果如下:

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.

删除线 {#deleteLine}

  • 在需要删除的文本或者单词前后使用双波浪号(~~)增加删除线。
~~世界是平坦的。~~ 我们现在知道世界是~~圆~~的。

效果如下: 世界是平坦的。 我们现在知道世界是的。

任务列表 {#taskList}

  • 可以创建带有复选框的项目列表。
  • 在任务列表项之前添加破折号-和方括号[ ],并在[ ]前面加上空格。要选择一个复选框,请在方括号[x]之间添加x
- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media
  • Write the press release
  • Update the website
  • Contact the media

使用Emoji表情 {#emoji}

  • 可以在Markdown中使用Emoji表情。
  • 将表情符号复制并粘贴到Markdown格式的文本中,或者键入emoji shortcodes。⛺😂
  • 可以使用此表情符号简码列表,但请记住,表情符号简码因应用程序而异。

Footnotes

  1. This is the first footnote.

  2. Here's one with multiple paragraphs and code.

    Indent paragraphs to include them in the footnote.

    { my code }

    Add as many paragraphs as you like.