简单的MarkDown 语法示例

1,072 阅读3分钟

这是我在掘金的第一篇log,主要关于MarkDown语法的学习,主要参考链接 Markdown 语法说明 (简体中文版)

MarkDown文本的优势

  • 纯文本格式,兼容所有系统和编辑器
  • 兼容HTML,并有大量工具支持多种文档格式的转换
  • 特殊字符自动转换,如<,>,&等符号.在HTML中,这些符号需要显式的被转换为&lt;,&amp;等,包括一些特殊符号如©可以直接写为&copy;

具体语法

换行

* 某行只有一个空格和制表符即会被视为是空行
* 文本插入处添加两个及以上空加回车格即可表示换行
* 转换为HTML标签 <br />

标题

# title 表示一级标题,即对应 <h1></h1> 标记
## title 二级标题
...
也可以使用 ## title ## 闭合的形式

区块引用 Blockquotes

区块引用使用>符号表示

this is a single line Blockquotes

this is a multi line Blockquotes
the next line
the third line

code

> this is a single line Blockquotes

> this is a multi line Blockquotes   
  the 2nd line  
  the 3rd line

引用区块中还可以嵌套,即使用>>表示

this is the first Blockquotes

这是嵌套引用

code

> this is the first Blockquotes
>
>> 这是嵌套引用  

引用区块中还可使用其他语法

this is a title

  1. item1
  2. item2
  3. item3

使用代码

 function dick(){
     console.log('Dick');
 }  

code

> # this is a title
> 1.  item1
> 2.  item2
> 3.  item3  
>
>使用代码
>  
>      function dick(){
>          console.log('Dick');
>      }

列表

无序列表: 使用*,+-表示

  • item1
  • item2
  • item3

code

* item1
* item2
* item3  
  • item1
    • item1_1
    • item1_2
  • item2
  • item3

code

+ item1
    + item1_1
    + item1_2
+ item2
+ item3  

有序列表:使用数字加.表示

  1. item1
  2. item2
  3. item3

code

1. item1
2. item2
3. item3 

序号不强制数字顺序 3. item1

  1. item2
  2. item3

code

3. item1
1. item2
3. item3 

若行首需要出现 29. XXXX 这种写法,则需要加反斜杠\,即   29\. XXXXX

如果列表中包含空行,则会在每项内容中添加<p></p>标记

code

* dick
* fish  

会被转换为:
<ul>
    <li>dick</li>
    <li>fish</li>
</ul>   

而  * dick
    * fish
会被转换为
<ul>
    <li><p>dick</p></li>
    <li><p>fish</p></li>
</ul> 

代码区块

缩进4个空格或者一个制表符即可表示

code:

function dick(){
    console.log('dick');
}   

即转换为
<pre><code>
function dick(){
    console.log('dick');
}
</code></pre>   

分隔线




code:

***
---
___     

链接

链接可以分为行内式和参考式两种形式

行内式:
this is my site

this is [my site](http://lang0527.cn 'lang0527.cn')

[]内为显式的内容,()内为具体的链接地址,''内为title值,可选    

参考式:
I get 10 times more traffic from Google than from Yahoo or MSN.

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"      

强调

this is a Dick
this is also a Dick
another Dick
other Dick

normal *Dick*
code:

this is a *Dick*   
this is also a _Dick_   
another **Dick**    
other __Dick__ 
normal \*Dick\*     

图片

无图片时显示的文字
这是个图片

![无图片时显示的文字](https://p1-jj.byteimg.com/tos-cn-i-t2oaga2asx/gold-user-assets/2018/3/29/16271a9d0ab55bb9~tplv-t2oaga2asx-image.image '这是个图片')      

其他

自动链接: example.com/

自动链接:
<http://example.com/>   

反斜杠转译符号\
.
(
!

\.  
\(  
\!

差不多就这些吧,还有些漏下的以后接着补上