当前位置: 代码网 > it编程>游戏开发>ar > Markdown语法手册—完整笔记整理

Markdown语法手册—完整笔记整理

2024年08月25日 ar 我要评论
markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(john gruber)。 它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的xhtml(或者html)文档。这种

markdown 是一种轻量级标记语言,创始人为约翰·格鲁伯(john gruber)。 它允许人们使用易读易写的纯文本格式编写文档,然后转换成有效的 xhtml(或者html)文档。这种语言吸收了很多在电子邮件中已有的纯文本标记的特性。

由于 markdown 的轻量化、易读易写特性,并且对于图片,图表、数学式都有支持,许多网站都广泛使用 markdown 来撰写帮助文档或是用于论坛上发表消息。 如 github、reddit、diaspora、stack exchange、openstreetmap 、sourceforge、简书等,甚至还能被使用来撰写电子书。

几乎所有markdown应用程序都支持john gruber原始设计文档中概述的基本语法。markdown处理器之间存在细微的差异和差异-尽可能在线内注明。

标题

要创建标题,请#在单词或短语的前面添加数字符号()。您使用的数字符号的数量应与标题级别相对应。例如,要创建标题级别三(<h3>),请使用三个数字符号(例如### my header)。

markdownhtml
# heading level 1<h1>heading level 1</h1>
## heading level 2<h2>heading level 2</h2>
### heading level 3<h3>heading level 3</h3>
#### heading level 4<h4>heading level 4</h4>
##### heading level 5<h5>heading level 5</h5>
###### heading level 6<h6>heading level 6</h6>

替代语法

或者,在文本下方的行上,添加任意数量的==标题级别1的--字符或标题级别2的字符。

markdownhtml
heading level 1
===============
<h1>heading level 1</h1>
heading level 2
---------------
<h2>heading level 2</h2>

段落

要创建段落,请使用空白行分隔一行或多行文本。您不应缩进带有空格或制表符的段落。

markdownhtml
i really like using markdown.

i think i'll use it to format all of my documents from now on.
<p>i really like using markdown.</p>

<p>i think i'll use it to format all of my documents from now on.</p>

换行

要创建换行符(<br>),请以两个或多个空格结束一行,然后键入return。

markdownhtml
this is the first line.  
and this is the second line.
<p>this is the first line.<br>
and this is the second line.</p>

着重

您可以通过使文本变为粗体或斜体来增加着重。

粗体

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

markdownhtml渲染输出
i just love **bold text**.i just love <strong>bold text</strong>.我只喜欢粗体字
i just love __bold text__.i just love <strong>bold text</strong>.我只喜欢粗体字
love**is**boldlove<strong>is</strong>bold大胆的

斜体

要斜体显示文本,请在单词或短语的前后添加一个星号或下划线。要斜体突出单词的中间部分,请在字母周围添加一个星号,中间不要带空格。

markdownhtml渲染输出
italicized text is the *cat's meow*.italicized text is the <em>cat's meow</em>.斜体文字是猫的叫声。
italicized text is the _cat's meow_.italicized text is the <em>cat's meow</em>.斜体文字是猫的叫声。
a*cat*meowa<em>cat</em>meow一个猫喵

粗体和斜体

要同时突出显示带有粗体和斜体的文本,请在单词或短语的前后添加三个星号或下划线。

markdownhtml渲染输出
this text is ***really important***.this text is <strong><em>really important</em></strong>.这段文字真的很重要
this text is ___really important___.this text is <strong><em>really important</em></strong>.这段文字真的很重要
this text is __*really important*__.this text is <strong><em>really important</em></strong>.这段文字真的很重要
this text is **_really important_**.this text is <strong><em>really important</em></strong>.这段文字真的很重要

块引用

要创建blockquote,请>在段落前面添加一个。

> dorothy followed her through many of the beautiful rooms in her castle.

呈现的输出如下所示:

桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。

具有多个段落的块引用

块引用可以包含多个段落。>在段落之间的空白行上添加一个。

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

呈现的输出如下所示:

桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。

女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。

嵌套块引用

块引用可以嵌套。>>在要嵌套的段落前面添加一个。

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

呈现的输出如下所示:

桃乐丝(dorothy)跟着她走过了她城堡中许多美丽的房间。

女巫请她清洗锅碗瓢盆,扫地,并用木柴取火。

具有其他元素的块引用

块引用可以包含其他markdown格式的元素。并非所有元素都可以使用-您需要进行实验以查看哪些元素有效。

> #### the quarterly results look great!
>
> - revenue was off the chart.
> - profits were higher than ever.
>
>  *everything* is going according to **plan**.

呈现的输出如下所示:

季度业绩看起来不错!

  • 收入超出了预期。
  • 利润比以往任何时候都高。

一切都按计划进行

清单

您可以将项目组织成有序和无序列表。

有序列表

要创建有序列表,请在订单项中添加数字和句点。数字不必按数字顺序排列,但列表应以数字开头。

markdownhtml渲染输出
1. first item
2. second item
3. third item
4. fourth item
<ol>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ol>
  1. 第一项
  2. 第二项
  3. 第三项
  4. 第四项
1. first item
1. second item
1. third item
1. fourth item
<ol>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ol>
  1. 第一项
  2. 第二项
  3. 第三项
  4. 第四项
1. first item
8. second item
3. third item
5. fourth item
<ol>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ol>
  1. 第一项
  2. 第二项
  3. 第三项
  4. 第四项
1. first item
2. second item
3. third item
    1. indented item
    2. indented item
4. fourth item
<ol>
<li>first item</li>
<li>second item</li>
<li>third item
<ol>
<li>indented item</li>
<li>indented item</li>
</ol>
</li>
<li>fourth item</li>
</ol>
  1. 第一项
  2. 第二项
  3. 第三项
    1. 缩进项
    2. 缩进项
  4. 第四项

无序列表

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

markdownhtml渲染输出
- first item
- second item
- third item
- fourth item
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ul>
  • 第一项
  • 第二项
  • 第三项
  • 第四项
* first item
* second item
* third item
* fourth item
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ul>
  • 第一项
  • 第二项
  • 第三项
  • 第四项
+ first item
* second item
- third item
+ fourth item
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
<li>fourth item</li>
</ul>
  • 第一项
  • 第二项
  • 第三项
  • 第四项
- first item
- second item
- third item
    - indented item
    - indented item
- fourth item
<ul>
<li>first item</li>
<li>second item</li>
<li>third item
<ul>
<li>indented item</li>
<li>indented item</li>
</ul>
</li>
<li>fourth item</li>
</ul>
  • 第一项
  • 第二项
  • 第三项
    • 缩进项
    • 缩进项
  • 第四项

在列表中添加元素

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

段落

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

呈现的输出如下所示:

  • 这是第一个列表项。
  • 这是第二个列表项。

    我需要在第二个列表项下面添加另一段。

  • 这是第三个列表项。

块引用

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

呈现的输出如下所示:

  • 这是第一个列表项。
  • 这是第二个列表项。

    在第二个列表项的下方,blockquote看起来不错。

  • 这是第三个列表项。

代码块

代码块通常缩进四个空格或一个制表符。当它们在列表中时,将它们缩进八个空格或两个选项卡。

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. 在第21行找到以下代码块:

    <html>
      <head>
        <title>test</title>
      </head>
    
  3. 更新标题以匹配您的网站名称。

图片

1.  open the file containing the linux mascot.
2.  marvel at its beauty.

    ![tux, the linux mascot](/assets/images/tux.png)

3.  close the file.

呈现的输出如下所示:

  1. 打开包含linux吉祥物的文件。
  2. 惊叹于它的美丽。

    tux,linux吉祥物

  3. 关闭文件。

代码

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

markdownhtml渲染输出
at the command prompt, type `nano`.at the command prompt, type <code>nano</code>. 在命令提示符下,键入nano

转义刻度线

如果要表示为代码的单词或短语包含一个或多个刻度线,可以通过将单词或短语括在双刻度线(``)中来对其进行转义。

markdownhtml渲染输出
``use `code` in your markdown file.``<code>use `code` in your markdown file.</code>use `code` in your markdown file.

代码块

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

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

呈现的输出如下所示:

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

水平线

要创建水平线***,请单独在一行上使用三个或更多的星号(),破折号(---)或下划线(___)。

***

---

_________________

所有这三个的渲染输出看起来都相同:

链接

要创建链接,请将链接文本括在方括号(例如[duck duck go])中,然后立即在url后面加上括号(例如(https://duckduckgo.com))中的url 。

my favorite search engine is [duck duck go](https://duckduckgo.com).

呈现的输出如下所示:

我最喜欢的搜索引擎是duck duck go。

添加标题

您可以选择为链接添加标题。当用户将鼠标悬停在链接上时,这将显示为工具提示。要添加标题,请将其括在url后面的括号中。

my favorite search engine is [duck duck go](https://duckduckgo.com "the best search engine for privacy").

呈现的输出如下所示:

我最喜欢的搜索引擎是duck duck go。

网址和电子邮件地址

要将url或电子邮件地址快速转换为链接,请将其括在尖括号中。

<https://markdown.p2hp.com>
<fake@example.com>

呈现的输出如下所示:

https://markdown.p2hp.com
fake@example.com

格式化链接

为了强调链接,请在方括号和括号之前和之后添加星号。

i love supporting the **[eff](https://eff.org)**.
this is the *[markdown guide](https://markdown.p2hp.com)*.

呈现的输出如下所示:

我喜欢支持eff
这是《markdown指南》。

参考样式链接

引用样式链接是一种特殊的链接,它使url在markdown中更易于显示和阅读。引用样式的链接分为两部分:与文本保持内联的部分以及在文件中其他位置存储的部分,以使文本易于阅读。

格式化链接的第一部分

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

尽管不是必需的,但您可以在第一组和第二组支架之间包含一个空格。第二组括号中的标签不区分大小写,可以包含字母,数字,空格或标点符号。

这意味着以下示例格式对于链接的第一部分大致相同:

  • [hobbit-hole][1]
  • [hobbit-hole] [1]

格式化链接的第二部分

引用样式链接的第二部分使用以下属性设置格式:

  1. 标签放在方括号中,后紧跟冒号和至少一个空格(例如[label]: )。
  2. 链接的url,您可以选择将其括在尖括号中。
  3. 链接的可选标题,您可以将其括在双引号,单引号或括号中。

这意味着以下示例格式对于链接的第二部分几乎都是等效的:

  • [1]: https://en.wikipedia.org/wiki/hobbit#lifestyle
  • [1]: https://en.wikipedia.org/wiki/hobbit#lifestyle "hobbit lifestyles"
  • [1]: https://en.wikipedia.org/wiki/hobbit#lifestyle 'hobbit lifestyles'
  • [1]: https://en.wikipedia.org/wiki/hobbit#lifestyle (hobbit lifestyles)
  • [1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> "hobbit lifestyles"
  • [1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> 'hobbit lifestyles'
  • [1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> (hobbit lifestyles)

您可以将链接的第二部分放在markdown文档中的任何位置。有些人将它们放在出现的段落之后,而其他人则将它们放在文档的末尾(例如尾注或脚注)。

将零件放在一起的示例

假设您添加一个url作为到段落的标准url链接,并且在markdown中看起来像这样:

in a hole in the ground there lived a hobbit. not a nasty, dirty, wet hole, filled with the ends
of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
eat: it was a [hobbit-hole](https://en.wikipedia.org/wiki/hobbit#lifestyle "hobbit lifestyles"), and that means comfort.

尽管它可能指向有趣的附加信息,但显示的url确实不会给现有的原始文本增加太多,除了使其难以阅读之外。要解决此问题,您可以改为设置网址格式:

in a hole in the ground there lived a hobbit. not a nasty, dirty, wet hole, filled with the ends
of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to
eat: it was a [hobbit-hole][1], and that means comfort.

[1]: <https://en.wikipedia.org/wiki/hobbit#lifestyle> "hobbit lifestyles"

在上述两种情况下,呈现的输出将相同:

在地上的一个洞里住着一个霍比特人。这不是一个肮脏,肮脏,潮湿的洞,里面充满蠕虫的末端和难闻的气味,也没有一个干燥,裸露,沙质的洞,里面没有东西可以坐下或进食:那是一个霍比特洞,意味着舒适。

链接html为:

<a href="https://en.wikipedia.org/wiki/hobbit#lifestyle" rel="external nofollow"  title="hobbit lifestyles">hobbit-hole</a>

图片

要添加图像,请添加感叹号(!),然后在括号中添加替代文本,并在括号中添加图像资源的路径或url。您可以选择在括号中的url之后添加标题。

![philadelphia's magic gardens. this place was so cool!](/assets/images/philly-magic-gardens.jpg "philadelphia's magic gardens")

呈现的输出如下所示:

费城的魔法花园。 这个地方真酷!

链接图像

要向图像添加链接,请将图像的markdown括在方括号中,然后在括号中添加链接。

[![an old rock in the desert](/assets/images/shiprock.jpg "shiprock, new mexico by beau rogers")](https://www.flickr.com/photos/beaurogers/31833779864/in/photolist-qv3rfw-34mt9f-a9cmfy-5ha3zi-9mskdv-o3hgjr-hwpute-4wmsj1-kuq8n-deshub-vssbd-6cqci6-8afcid-zsjwt-nnfsgb-dpdwzj-bn9jgn-5htsxy-6cuhal-a4utxb-ugpum-kupso-fblnm-6cumpy-4wmsc9-8a7d3t-83kjev-6cq2bk-nnushj-a78rqh-nw3nvt-7aq2qf-8wwbso-3nnceh-ugskp-4mh4kh-bbeeqh-a7bime-q3pttf-brfpgb-cg38zw-bxmzc-njpeld-f58lmo-bxmyg-bz8aai-bxntnt-bxmyi-bxmy6-bxmyv)

呈现的输出如下所示:

沙漠中的一块老石头

转义字符

要显示原义字符,否则将用于设置markdown文档中的文本格式\,请在字符前面添加反斜杠()。

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

呈现的输出如下所示:

*如果没有反斜杠,这将是无序列表中的项目符号。

你可以转义的字符

您可以使用反斜杠转义以下字符。

字符名称
\反斜杠
`刻度线
*星号
_下划线
{}大括号
[]中括号
()括号
#井号
+加号
-减号(连字符)
.
!感叹号
|管道
(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com