您的位置:首页 > 其它

Markdown 简明语法手册

2016-10-17 00:55 330 查看

Markdown 简明语法手册


本文原文http://www.jianshu.com/p/fdb5cbdaf244

根据个人使用情况有所修改。



Markdown是一种轻量级标记语言,简称md。创始人为约翰·格鲁伯(John Gruber)。它允许人们“使用易读易写的纯文本格式编写文档,然后转换成有效的XHTML(或者HTML)文档”。这种语言吸收了很多在电子邮件中已有的纯文本标记的特性。——维基百科


1. 标题

# 一级标题
## 二级标题
...
###### 六级标题

一级标题,一个#号

二级标题

三级标题

......

六级标题,六个#号

2. 列表

- 无序列表

1. 有序列表


我是无序列表:减号加空格

我是有序列表:直接数字加点句号。

3. 引用

> 引用内容


引用内容


4. 粗体和斜体

**两个星号是粗体**
*一个星号是斜体*

Hello World!

Hello World!

5.链接与图片

<http://xhstormr.github.io/>
<XhstormR@foxmail.com>

http://xhstormr.github.io/

XhstormR@foxmail.com

链接直接输入,网址,邮箱用尖括号包着自动就有了。

插入链接有两种方法:一种是行间文字链接,一种是行外文字链接。

[link text](http://example.com/ "optional title")

[link text][id]
[id]: http://example.com/  "optional title here"

链接文字内容

[链接文字内容][id]

[id]: http://example.com/ "optional title here"

插入图片

![](/path/to/img.jpg "optional title")


[![][jane-eyre-pic]{ImgCap}{/ImgCap}][jane-eyre-douban]

[jane-eyre-pic]: http://img3.douban.com/mpic/s1108264.jpg [jane-eyre-douban]: http://book.douban.com/subject/1141406/[/code] 

6. 插入代码

​ 如果段落开头使用了tab,会被认为是代码块。

<php>
echo “hello world";
</php>

简单地说是用三个“ ` ”加上语言表示,比如javascript,phphtml等等。

行内代码:用点号`引起来就好

Use the `printf()` function.

7. 分割线和删除线

在一行之内用三个以上的星号,减号,下划线建立分割线,用2个~建立删除线。

8. 代码块和语法高亮

```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```

function(){
alert('hello world!')
}


语法详解

段落、标题、区块代码

区块引用则使用 email 形式的 '
>
' 角括号。

Markdown 语法:

A First Level Header
====================
A Second Level Header
---------------------

Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.

The quick brown fox jumped over the lazy
dog's back.
### Header 3

> This is a blockquote.
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote

一串文字在下面加上一串等号也是一级标题

一串文字加上一串减号就是二级标题

换行可以直接用回车键

换行可以直接用回车键

三级标题:好像只能用三个#了


这是一段引用.

此乃引用中的第二行,需要回车后另起一行写个>

在引用里面写两个#就成了引用中的二级标题


修辞和强调

Markdown 使用星号和底线来标记需要强调的区段。

Markdown 语法:

Some of these words *are emphasized*.
Some of these words _are emphasized also_.
Use two asterisks for **strong emphasis**.
Or, if you prefer, __use two underscores instead__.

Some of these words are emphasized.

Some of these words are emphasized also.

Use two asterisks for strong emphasis.

Or, if you prefer, use two underscores instead.

列表

无序列表使用星号、加号和减号来做为列表的项目标记,这些符号是都可以使用的,使用星号:

* Candy.
* Gum.
* Booze.


我是无序列表

加号:

+ Candy.
+ Gum.
+ Booze.


前面加一个+号也是无序列表

和减号

- Candy.
- Gum.
- Booze.


前面加一个减号还是无序列表

有序的列表则是使用一般的数字接着一个英文句点作为项目标记:

1\. Red
2\. Green
3\. Blue

注意. 本文档的序号都是使用
数字\.
的方式写就的。

链接

Markdown 支援两种形式的链接语法: 行内 和 参考 两种形式,两种都是使用角括号来把文字转成连结。

行内形式是直接在后面用括号直接接上链接:

This is an [example link](http://example.com/).

This is an example link.

你也可以选择性的加上 title 属性:

This is an [example link](http://example.com/ "With a Title").

This is an example link.(悬停会有提示,看编辑器而定)

参考形式的链接让你可以为链接定一个名称,之后你可以在文件的其他地方定义该链接的内容:

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"

图片

图片的语法和链接很像。

行内形式(title 是选择性的):

![](图片路径 "Title"){ImgCap}alt text{/ImgCap}

行外注脚形式:

![][id]{ImgCap}alt text{/ImgCap}

[id]: /path/to/img.jpg "Title"

代码

在一般的段落文字中,你可以使用反引号 ``
来标记代码区段,区段内的
&
<
>` 都会被自动的转换成 HTML 实体,这项特性让你可以很容易的在代码区段内插入 HTML 码:

I strongly recommend against using any `<blink>` tags.

I wish SmartyPants used named entities like `—`
instead of decimal-encoded entites like `—`.

如果要建立一个已经格式化好的代码区块,只要每行都缩进 4 个空格或是一个 tab 就可以了,而
&
<
>
也一样会自动转成 HTML 实体。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: