AeonJh
文章4
标签6
分类2
Markdown基础语法学习

Markdown基础语法学习

这是AeonJh的第一篇博客,关于markdown语法的基础使用,本文仅供本人练习Markdown !

如果是为了快速入手可以参考官网Markdown 语法速查表 | Markdown 官方教程

Markdown 标题语法

  • 使用 #来创建标题,#的数量代表标题的级别。

    因标题预览效果会导致目录自动添加,所以此处去除预览鲜果。

Markdown语法 HTML
# Heading level 1 <h1>Heading level 1</h1>
## Heading level 2 <h2>Heading level 1</h2>
### Heading level 3 <h3>Heading level 1</h3>
#### Heading level 4 <h4>Heading level 1</h4>
##### Heading level 5 <h5>Heading level 1</h5>
###### Heading level 6 <h6>Heading level 1</h6>

也可选用 ==号来创建一级标题,使用 -- 来创建二级标题。


Markdown 段落

  • 使用空白行讲一行或多行文本进行分段
Markdown语法 HTML 预览效果

hello,world!

tomorrow will be better!

<p>hello,world!</p> <p>tomorrow will be better!</p>

hello,world!

tomorrow will be better!

注意: 请不要用空格(spaces)或者制表符(Tabs)对段落进行缩进

换行感觉不是那么重要,此处不再赘述。Markdown本身不提供单元格换行,但是,Markdown是兼容HTML的,因此,我们可以使用 <br> 来实现单元格换行。想获得更多信息可以自行查阅官网Markdown 换行语法 | Markdown 官方教程


Markdown 强调语法

粗体(Bold)

Markdown语法 HTML 预览效果
I love **bold text** . I love <strong>bold text</strong> . I love bold text .
I love __bold text__ . I love <strong>bold text</strong> . I love bold text .
Love**is**bold Love<strong>is</strong>bold Loveisbold

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

斜体(Italic)

Markdown语法 HTML 预览效果
I love *bold text* . I love <em>bold text</em> . I love bold text .
I love _bold text_ . I love <em>bold text</em> . I love bold text .
Loveis*bold* Loveis<em>bold</em> Loveisbold

粗体(Bold)和斜体(Italic)

Markdown语法 HTML 预览效果
I love ***bold text*** . I love <strong><em>bold text</em></strong> . I love bold text .
I love ___bold text___ . I love <strong><em>bold text</em></strong> . I love bold text .
This love***is***bold This love<strong>is</em></strong>bold This loveisbold

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


Markdown 引用语法

  • 要创建块引用,请在段落前添加一个 > 符号
 > Dorothy followed her through many of the beautiful rooms in her castle.
  • 效果如下:

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

多个段落块的引用

  • 块引用可以包含多个段落。只需为段落之间的空白行添加一个 > 符号。
> Hello,world!
>
> I love you!
  • 效果如下:

Hello,world!

I love you!

嵌套块引用

> Hello,world!
>
>> I love you!
  • 效果如下:

Hello,world!

I love you!

带有其它元素的块引用

  • 块引用可以包含其他 Markdown 格式的元素。并非所有元素都可以使用,你需要进行实验以查看哪些元素有效。
> #### Have a nice day!
>
> - This is a test.
>
>  *Everything* is **going** according to ***plan***.
  • 效果如下:

Have a nice day!

  • This is a test.

Everything is going according to plan.


Markdown 列表语法

有序列表

  • 要创建有序列表,请在每个列表项前添加数字并紧跟一个英文句点。数字不必按数学顺序排列,但是列表应当以数字 1 起始。
Markdown语法 HTML 预览效果
1. First item
2. Second item
3. Third item
<ol><li>First item</li><li>Second item</li><li>Third item</li></ol> 1. First item
2. Second item
3. Third item
1. First item
1. Second item
1. Third item
<ol><li>First item</li><li>Second item</li><li>Third item</li></ol> 1. First item
2. Second item
3. Third item
1. First item
3.Second item
2. Third item
<ol><li>First item</li><li>Second item</li><li>Third item</li></ol> 1. First item
2. Second item
3. Third item

无序列表

  • 要创建无序列表,请在每个列表项前面添加破折号 -、星号 * 或加号 + 。缩进一个或多个列表项可创建嵌套列表。
Markdown语法 HTML 预览效果
- First item
- Second item
- Third item
    - Indented item
    - Indenteditem item
- Fourth item
<ul><li>First item</li><li>Second item</li><li>Third item<ul><li>Indented item</li><li>Indenteditem</li></ul></li><li>Fourth item</li></ul>
  • First item
  • Second item
  • Third item
    • Indented item
    • Indenteditem
  • Fourth item

在列表中嵌套其他元素

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

    此处只给出代码块示意

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


Markdown 代码语法

  • 要将单词或短语表示为代码,请将其包裹在反引号 ` 中。

    注意: 如果你要表示为代码的单词或短语中包含一个或多个反引号,则可以通过将单词或短语包裹在双反引号``中。

代码块

  • 要创建代码块,请将代码块的每一行缩进至少四个空格或一个制表符。
    <html>
      <head>
      </head>
    </html>

注意: 要创建不用缩进的代码块,请使用 围栏式代码块

你可以在代码块之前和之后的行上使用三个反引号```或三个波浪号~~~

```
{
“firstName”: “John”,
“lastName”: “Smith”,
“age”: 25
}
```

语法高亮

你可以在代码块的反引号```或波浪号~~~旁边指定一种语言。

```yml
{
“firstName”: “John”,
“lastName”: “Smith”,
“age”: 25
}
```


  • 要创建分隔线,请在单独一行上使用三个或多个星号***、破折号---或下划线___,并且不能包含其他内容。

    注意: 为了兼容性,请在分隔线的前后均添加空白行。


Markdown 链接语法

  • 链接文本放在中括号内,链接地址放在后面的括号中,链接title可选

  • 超链接Markdown语法代码:[超链接显示名](超链接地址 "超链接title")

  • 对应的HTML代码:<a href="超链接地址" title="超链接title">超链接显示名</a>

  • 例如:这是一个链接 [Markdown语法](https://markdown.com.cn)。

    这是一个链接 Markdown语法


Markdown 图片语法

  • 要添加图像,请使用感叹号!, 然后在方括号增加替代文本,图片链接放在圆括号里,括号里的链接后可以增加一个可选的图片标题文本

  • 插入图片Markdown语法代码:![图片alt](图片链接 "图片title")

  • 对应的HTML代码:<img src="图片链接" alt="图片alt" title="图片title">

  • 例如 :![图片](https://s2.loli.net/2023/05/15/JSXVAt48D9ZHwox.jpg "Spider Man")

    图片

图片链接

  • 给图片增加链接,请将图像的Markdown 括在方括号中,然后将链接添加在圆括号中。
  • [![图片](https://s2.loli.net/2023/05/15/JSXVAt48D9ZHwox.jpg "Spider Man")](https://wallhaven.cc/w/pko8lm)

    图片

Markdown 转义字符语法:

详细的转义字符语法建议参考Markdown 转义字符语法 | Markdown 官方教程


Markdown 内嵌 HTML 标签

由于本人并未学习过HTML,因此此处不再详述。

  • 对于 Markdown 涵盖范围之外的标签,都可以直接在文件里面用 HTML 本身。如需使用 HTML,不需要额外标注这是 HTML 或是 Markdown,只需 HTML 标签添加到 Markdown 文本中即可。

行级內联标签

  • HTML 的行级內联标签如 <span><cite><del> 不受限制,可以在 Markdown 的段落、列表或是标题里任意使用。

区块标签

  • 区块元素──比如 <div><table><pre><p> 等标签,必须在前后加上空行,以便于内容区分。

Markdown 表格

  • 要添加表格,请使用三个或多个连字---创建每列的标题,并使用管道|分隔每列。你也可以选择在表的任一端添加管道。

    Tip: 快速使用连字符和管道创建表,尝试使用此工具Markdown Tables Generator

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

对齐

  • 你可以通过在标题行中的连字符的左侧,右侧或两侧添加冒号:,将列中的文本对齐到左侧,右侧或中心。
| Syntax      | Description | Test Text     |
| :---        |    :----:   |          ---: |
| Header      | Title       | Here's this   |
| Paragraph   | Text        | And more      |
Syntax Description Test Text
Header Title Here’s this
Paragraph Text And more

更多规则请参照Markdown 表格 | Markdown 官方教程


Markdown 脚注

  • 脚注可以为文档添加注释和参考,而不会使文档正文混乱。要创建脚注参考,请在方括号[^1]内添加插入符号和标识符。在括号内使用另一个插入符号和数字添加脚注,并用冒号和文本[^1]: My footnote.

    注意: 标识符可以是数字或单词,但不能包含空格或制表符。

This is a identifier[^footnote]

[^footnote]:This is the identifier's footnote.

This is a identifier[^footnote]

[^footnote]:This is the identifier’s footnote.


markdown 删除线

  • 你可以通过在单词中心放置一条水平线来删除单词。结果看起来像这样。此功能使您可以指示某些单词是一个错误,要从文档中删除。若要删除单词,请在单词前后使用两个波浪号~~

Markdown 任务列表语法

  • 任务列表使你可以创建带有复选框的项目列表。在支持任务列表的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 使用 Emoji 表情

  • 有两种方法可以将表情符号添加到Markdown文件中:将表情符号复制并粘贴到Markdown格式的文本中,或者键入_emoji shortcodes_

  • 在大多数情况下,您可以简单地从Emojipedia 等来源复制表情符号并将其粘贴到文档中。

Tip: 如果您使用的是静态网站生成器,请确保将HTML页面编码为UTF-8。

去露营了! :tent: 很快回来。

真好笑! :joy:

去露营了! ⛺️ 很快回来。

真好笑! 😂

注意: 你可以使用此表情符号简码列表,但请记住,表情符号简码因应用程序而异。


本篇文章到这里就结束啦~ Markdown语法的使用还得在日常使用中多多熟悉,感谢您的阅读!

本文作者:AeonJh
本文链接:https://aeonjh.top/2023/01/06/About%20the%20basic%20usage%20of%20Markdown/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可
×