什么是 Markdown
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式。
官方文档:By John Gruber 注:本文档直译自原官方文档,并稍作润色。如果感觉难以理解,请参此照图文快速上手文档。
Headers(标题)
Markdown支持两种样式的标题Setext和atx。
Setext样式标题使用等号(对于一级标题)和破折号(用于二级标题)“带下划线”。
例如:
This is an H1
=============
This is an H2
-------------
任何数量的下划线=或-将会工作。Atx风格的标题在行开头使用1-6个散列字符,对应于标题级别1-6。例如:
# This is an H1
## This is an H2
###### This is an H6
或者,您可以“闭合”atx风格的标题。这是纯粹的化妆品 - 如果你认为它看起来更好,你可以使用它。
# This is an H1 #
## This is an H2 ##
### This is an H3 ######
输出:
<h1>This is an H1</h1>
<h2>This is an H2</h2>
<h6>This is an H6</h6>
Blockquotes(引用文字)
Markdown使用电子邮件风格的>字符进行块引用。如果您熟悉引用电子邮件中的文字段落,那么您将了解如何在Markdown中创建一个blockquote。
> Blockquotes
> Blockquotes
Markdown允许你偷懒,只把>只需要标记段落的第一行:
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.
Blockquotes可以嵌套(即一个blockquote-in-a-blockquote),增加额外的级别>:
> This is the first level of quoting.
>
> > This is nested blockquote.
>
> Back to the first level.
Blockquotes可以包含其他Markdown元素,包括头文件,列表和代码块:
> ## This is a header.
> 
> 1.   This is the first list item.
> 2.   This is the second list item.
> 
> Here is some example code:
>     return shell_exec("echo $input | $markdown_script");
Lists(列表)
Markdown支持有序(编号)和无序(项目符号)列表。
无序列表使用星号,加号和连字符 - 可互换 - 作为列表标记:
* Red
* Green
* Blue
// 相当于:
+ Red
+ Green
+ Blue
// 或者:
- Red
- Green
- Blue
有序列表使用数字后跟期间:
1. Bird
2. McHale
3. Parish
Code Blocks(代码块)
代码块继续,直到没有缩进的一行(或文章的末尾)。
This is a normal paragraph:
    This is a code block.
引用符号缩进为0/4/8的和时候分别会有不同的渲染方式
*   A list item with a blockquote:
    > This is a blockquote
    > inside a list item.
---
*   A list item with a blockquote:
        > This is a blockquote
        > inside a list item.
在代码块中,&符号( )和尖括号(< >)将自动转换为HTML实体。这使得使用Markdown包含示例HTML源代码非常容易 - 只需将其粘贴并缩进,Markdown将处理编码&和尖括号。例如:
    <div class="footer">
        © 2004 Foo Corporation
    </div>
Horizontal Rules(分割线)
* * *
***
*****
- - -
---------------------------------------
Span Elements(链接元素)
Markdown支持两种风格的链接:内联和引用。
在两种样式中,链接文本由[方括号]分隔。
This is [an example](http://example.com/ "Title") inline link.
See my [About](/about/) page for details.
或者使用自动链接:
<http://example.com/>
<a href="http://example.com/">http://example.com/</a>
您可以选择使用一个空格分开括号集:
This is [an example] [myBlog] reference-style link.
然后,在文档的任何地方,您可以自己定义一个这样的链接标签:
[myBlog]: http://example.com/  "Optional Title Here"
链接定义可以放置在您的Markdown文档的任何位置。我倾向于将它们放在他们使用的每个段落之后,但如果需要,可以将它们全部放在文档的末尾,就像脚注一样。
I get 10 times more traffic from [Google] [1] than from
[Yahoo] [2] or [MSN] [3].
  [1]: http://google.com/        "Google"
  [2]: http://search.yahoo.com/  "Yahoo Search"
  [3]: http://search.msn.com/    "MSN Search"
使用隐式链接名称快捷方式,您可以改为写:
I get 10 times more traffic from [Google][] than from
[Yahoo][] or [MSN][].
  [google]: http://google.com/        "Google"
  [yahoo]:  http://search.yahoo.com/  "Yahoo Search"
  [msn]:    http://search.msn.com/    "MSN Search"
Emphasis(强调)
Markdown将星号*和下划线_作为重点的指示。您可以使用您喜欢的任何风格; 唯一的限制是必须使用相同的字符来打开和关闭强调范围。
一个*或_将被<em>标签包装;
两个*或_将包含一个<strong>标签。例如:
*single asterisks*
_single underscores_
**double asterisks**
__double underscores__
输出:
<em>single asterisks</em>
<em>single underscores</em>
<strong>double asterisks</strong>
<strong>double underscores</strong>
Code(代码)
” ` “包裹单词,” `` “包裹段落,” ``` “包裹片段
Use the `printf()` function.
``There is a literal backtick (`) here.``
A backtick-delimited string in a code span: `` `foo` ``
Images(图片)
诚然,将图像设置为纯文本格式是非常困难的。
Markdown使用旨在类似于链接语法的图像语法,允许两种样式:内联和引用。
内联图像语法如下所示:


感叹号:!;
后面是一组方括号,包含alt图像的属性文本;
后跟一组括号,包含图像的URL或路径,以及title用双引号或单引号括起来的可选属性。
引用风格的图像语法如下所示: 其中“id”是定义的图像引用的名称。图像引用使用与链接引用相同的语法定义:
![Alt text][id]
[id]: url/to/image  "Optional title attribute"
在撰写本文时,Markdown没有指定图像尺寸的语法; 如果这对您很重要,您只需使用常规HTML <img>标签即可。
Backslash Escapes(反斜杠逃生/转译?)
Markdown允许您使用反斜杠转义来生成文字字符,否则Markdown的格式化语法将具有特殊的含义。例如,如果要用文字星号(而不是HTML <em>标签)来包围字词,则可以在星号之前使用反斜杠,如下所示:
\*literal asterisks\*
Markdown为以下字符提供反斜杠转义:
\   backslash
`   backtick
*   asterisk
_   underscore
{}  curly braces
[]  square brackets
()  parentheses
#   hash mark
+   plus sign
-   minus sign (hyphen)
.   dot
!   exclamation mark