DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> WEB網站前端 >> WEB前端代碼
Markdown 簡明語法手冊(含語法詳解)
編輯:WEB前端代碼     

Markdown 是一種輕量級標記語言,簡稱 md,創始人為約翰·格魯伯(John Gruber)。它讓人們「以易讀易寫的純文字格式撰寫文件,再轉換成有效的 XHTML 或 HTML」,並吸收了電子郵件中既有的純文字標記慣例。——維基百科

以下依個人使用習慣整理,分為「簡明語法」與「語法詳解」兩部分。

一、標題

# 一級標題
## 二級標題
...
###### 六級標題

一級標題,一個 # 號

二級標題

三級標題

……

六級標題,六個 # 號

二、列表

- 無序表列
1. 有序表列
  • 我是無序表列:減號加空格
  1. 我是有序表列:數字加句點。

三、引用

> 引用內容

引用內容

四、粗體與斜體

**兩個星號是粗體**
*一個星號是斜體*

Hello World!

Hello World!

五、連結與圖片

<https://hovertree.com/>
<hello@hovertree.com>

https://hovertree.com/
hello@hovertree.com

網址與信箱直接用角括號包起來,就會自動變成連結。

插入連結有兩種寫法:行內式與參考式。

[link text](https://hovertree.com/ "optional title")

[link text][id]
[id]: https://hovertree.com/ "optional title here"

行內式的連結文字內容。

參考式的[連結文字內容][id]
[id]: https://hovertree.com/ "optional title here"

插入圖片:

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

範例圖

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

[jane-eyre-pic]: https://hovertree.com/hvtimg/bjafaj/9h2t2lm5.jpg
[jane-eyre-douban]: https://hovertree.com/jq/hovertreeimg/

六、插入程式碼

如果段落開頭使用 Tab 縮排,會被視為程式碼區塊。

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

另一種寫法是用三個反引號加上語言名稱,例如 javascript、php、html 等。

行內程式碼則用單個反引號包起來:

Use the `printf()` function.

七、分隔線與刪除線

一行內放三個以上的星號、減號或底線即可建立分隔線;用兩個 ~ 包住文字可建立刪除線。

八、程式碼區塊與語法高亮

```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
function(){ alert('hello world!') }

語法詳解

段落、標題與區塊引用

標題除了用 #,也可以用「文字下方接一串等號或減號」的 Setext 風格:

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

一串文字下方加上等號,也是一級標題

一串文字下方加上減號,就是二級標題

段落中的換行可以直接按 Enter。

三級標題

這是一段引用。

引用中的第二行,需要 Enter 後另起一行再寫一個 >。

在引用裡寫兩個 #,就成了引用中的二級標題

強調與修辭

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 [hovertree link](https://hovertree.com/).

也可以選擇性加上 title 屬性:

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

滑鼠懸停時會顯示提示(視編輯器而定)。

參考式:先為連結取一個名稱,之後可在文件其他位置統一定義它的內容,適合同一個連結重複出現多次的情況。

I get 10 times more traffic from [HoverTree][1] than from [Keleyi][2] or [HoverClock][3].

[1]: https://hovertree.com/ "HoverTree"
[2]: https:/// "Keleyi"
[3]: https://hovertree.com/texiao/hoverclock/ "HoverClock"

圖片

圖片語法與連結幾乎相同,只是前面多一個驚嘆號。

行內式(title 為選填):

![alt text](圖片路徑 "Title"){ImgCap}{/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 實體。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved