Markdown小冊


概述

Markdown是一門輕量級標記語言,用簡潔的語法代替了手動排版,讓我們更專注於寫作。簡而言之,我們通過一些符號告訴計算機「應當怎樣排列一段文字」。

許多軟件對Markdown的支持存在不一致的情況,我們將參考廣泛使用的GitHub Flavored Markdown,對常用的語法作出簡單的介紹,並附上示例與一些參考鏈接。

  • 組織:所有的示例都被包含在引用塊中,且示例代碼包括生成引用塊的部分。

    轉義:插入必要的空格分隔語法使用的符號,希望表示其本義時,使用轉義字符

塊級元素

塊級元素占據其水平方向的所有空間,只能夠縱向排列。一篇文章由數個縱向排列的塊構成;其中一些是容器塊,能夠包含其它的塊;另一些只能夠包含特定的內容。插入必要的空行分隔兩個塊,空行不會被渲染。

段落

輸入一行或連續的多行文字即可建立一個段落。段內換行時,應當在上一行的末尾留下兩個空格,以確保換行成功;否則,一個符合標准的解析器可以選擇將單次換行渲染為一個空格。

  • 注意:示例代碼包含三個段落,第二個段落由兩行組成,其第一行末尾存在兩個空格。
Once is the inspirational tale of two kindred spirits who find each other on the bustling streets of Dublin.

One is a street musician who lacks the confidence to perform his own songs.  
The other is a young mother trying to find her way in a strange new town.

As their lives intertwine, they discover each others talents and push one another to realize what each had only dreamt about before. Once is their inspiring story.

Once is the inspirational tale of two kindred spirits who find each other on the bustling streets of Dublin.

One is a street musician who lacks the confidence to perform his own songs.
The other is a young mother trying to find her way in a strange new town.

As their lives intertwine, they discover each others talents and push one another to realize what each had only dreamt about before. Once is their inspiring story.

標題

在行首放置一到六個#建立標題。標題僅占用一行,無需多余空行分隔下文的塊。

# Once
## Glen Hansard
## Marketa Irglova
###### Once is their inspiring story

Once

Glen Hansard

Marketa Irglova

Once is their inspiring story

引用塊

在行首放置一個>以建立引用塊。若引用的內容超過一行,>應當被放置到每一行的行首。

  • 注意:若引用塊后的內容能夠與其末尾的內容組成一個塊,這部分內容也會被包括到引用塊中,參考示例
A thirty-something busker (Guy) performs with his guitar on Grafton Street, a Dublin shopping district and chases a man who steals his money.  

> Lured by his music,  
a young Czech flower seller (Girl) talks to him about his songs. 

A thirty-something busker (Guy) performs with his guitar on Grafton Street, a Dublin shopping district and chases a man who steals his money.

Lured by his music,
a young Czech flower seller (Girl) talks to him about his songs.

列表

一個列表由至少一個列表項組成,連續且使用相同符號的列表項將被包括到同一個列表中。列表項是容器,通過額外的縮進將一個列表項擴展至多行,參考示例

  • 注意:若列表項后的內容能夠與其末尾的內容組成一個塊,這部分內容也會被包括到表項中,參考示例

無序列表

通過一個*+-建立一個列表項。

+ Delighted to learn that he repairs hoovers, Girl insists that Guy fix her broken hoover.
+ The next day Girl returns with her broken hoover and tells Guy that she is also a musician.
  
  At a music store where Girl regularly plays piano, Guy teaches her one of his songs ("Falling Slowly"); they sing and play together.

  • Delighted to learn that he repairs hoovers, Girl insists that Guy fix her broken hoover.

  • The next day Girl returns with her broken hoover and tells Guy that she is also a musician.

    At a music store where Girl regularly plays piano, Guy teaches her one of his songs ("Falling Slowly"); they sing and play together.

有序列表

在序號之后接上一個.)即可建立一個列表項。

1. Guy invites her to his father's shop, and on the bus home musically answers Girl's question about what his songs are about: 
2. a long-time girlfriend who cheated on him,  
then left ("Broken Hearted Hoover Fixer Sucker Guy").

  1. Guy invites her to his father's shop, and on the bus home musically answers Girl's question about what his songs are about:
  2. a long-time girlfriend who cheated on him,
    then left ("Broken Hearted Hoover Fixer Sucker Guy").

代碼塊

通過一對```~~~建立代碼塊。在首行的末尾可添加別名(Alias)以啟用對應的語法高亮方案。若高亮功能由highlight.js提供,在這里能夠找到可用的別名。若高亮功能由prism.js提供,在這里能夠找到可用的別名。

``` rust
impl Life for Love<Guy, Girl> {
    fn life() -> ! {
        panic!();
    }
}
fn main() {
    Love::<Guy, Girl>::life();
}
```
impl Life for Love<Guy, Girl> {
    fn life() -> ! {
        panic!();
    }
}
fn main() {
    Love::<Guy, Girl>::life();
}

數學公式

  • 注意:數學公式不是GFM的一部分。

通過一對$$建立公式塊,它接受 Tex/LaTeX 代碼。若這個功能由MathJax提供,在這里能夠找到可用的命令。

$$
\frac{0}{0},\frac{\infty}{\infty}\Leftarrow\begin{cases}
	0\times\infty\Leftarrow\begin{cases}
		1^\infty\\
		\infty^0\\
		0^0
	\end{cases}\\
	\infty-\infty
\end{cases}
$$

\[\frac{0}{0},\frac{\infty}{\infty}\Leftarrow\begin{cases} 0\times\infty\Leftarrow\begin{cases} 1^\infty\\ \infty^0\\ 0^0 \end{cases}\\ \infty-\infty \end{cases} \]

表格

表格的一行由數個|分隔的小格組成,可包含文字與內聯元素。特別的,第二行表示分隔行(delimiter row),可包含數個-以及可選的前后綴:,用於指定所在列的對齊方式。

| cats  | always |           meow |
| :---- | :----: | -------------: |
| life  | always |      works out |
| music | always | evoke memories |
cats always meow
life always works out
music always evoke memories

腳注

腳注由注解與引用兩部分組成;注解部分會被渲染至頁面的底部,引用部分會被渲染為一個鏈接,可多次使用;它們由一個標簽相關聯。

"Falling Slowly"[^falling-slowly] won the 2007 Academy Award for Best Original Song. 

[^falling-slowly]: "Falling Slowly", available at [NeteaseMusic](https://music.163.com/#/song?id=4340758). 

"Falling Slowly"[1] won the 2007 Academy Award for Best Original Song.

分隔線

輸入 ***--- 即可生成一條水平分隔線。

At the shop, Guy introduces Girl to his father and takes her to his room, but when he asks her to stay the night, Girl feels insulted and leaves. 

---

The next day, they reconcile and spend the week writing, rehearsing and recording songs. 

At the shop, Guy introduces Girl to his father and takes her to his room, but when he asks her to stay the night, Girl feels insulted and leaves.


The next day, they reconcile and spend the week writing, rehearsing and recording songs.

行內元素

行內元素依照文字的順序排列,擁有確定的高度與寬度。

鏈接

  • 注意:多數網站會為標題生成一個錨(Anchor),鏈接可以借此在頁面內跳轉;但錨的生成不是GFM的一部分。

一個鏈接包含三個要素:文字、地址、標題,后兩者是可選的。通常,光標懸停至鏈接上方時,標題以工具提示的方式呈現。若同一個鏈接被多次用到,應當使用引用鏈接

Girl rehearses lyrics for one of Guy's songs ("[If You Want Me](<http://music.163.com/song?id=4340760> "Music From The Motion Picture Once")"), singing to herself while walking down the street; at a party, people perform impromptu (including "Gold"). 

Girl rehearses lyrics for one of Guy's songs ("If You Want Me"), singing to herself while walking down the street; at a party, people perform impromptu (including "Gold").

鏈接地址

規范的,一個Autolink由一對<>包括的URI構成;但一個符合標准的解析器也可以選擇自動識別沒有被<>包括的URI。

The place where the dream originated: <http://primary-yuiko.com/>. 

The place where the dream originated: http://primary-yuiko.com/.

引用鏈接

通過一個標簽將鏈接的 地址與標題文字 聯系起來,實現鏈接的復用。當文字與標簽相同時,可以省略文字部分的標簽。

Guy works on "[Lies]", a song about his [ex-girlfriend][Lies], who moved to London. Girl encourages him to win her back. Invited to the woman's home, Guy discovers that Girl has a toddler and lives with her mother. 

[Lies]: <http://music.163.com/song?id=4340768> "Music From The Motion Picture Once"

Guy works on "Lies", a song about his ex-girlfriend, who moved to London. Girl encourages him to win her back. Invited to the woman's home, Guy discovers that Girl has a toddler and lives with her mother.

圖片

類似於鏈接,圖片也包含文字、地址、標題三部分。文字部分在圖像加載失敗或語音朗讀時被使用。通常,光標懸停至圖片上方時,標題以工具提示的方式呈現。

![FIGURE: Guy talks with Girl after getting their album](<https://img2020.cnblogs.com/blog/2084381/202105/2084381-20210524003408549-694219766.png> "The Motion Picture Once")

FIGURE: Guy talks with Girl after getting their album

強調

一對*_包括的文字將被強調,詞組中的_不會受到影響。

Guy decides to move to London, but he wants to record a demo of his songs to take with him and asks Girl to record it with him. They secure a bank loan and reserve time at a recording studio. Guy learns Girl has a husband in the _Czech Republic_.

Guy decides to move to London, but he wants to record a demo of his songs to take with him and asks Girl to record it with him. They secure a bank loan and reserve time at a recording studio. Guy learns Girl has a husband in the Czech Republic.

加粗

一對**__包括的文字將被加粗,詞組中的__不會受到影響。

When he asks if she still loves her husband, Girl answers in Czech, "Miluji tebe" ("**I love you**"), but coyly declines to translate. After recruiting a band from other buskers, they go into the studio to record. 

When he asks if she still loves her husband, Girl answers in Czech, "Miluji tebe" ("I love you"), but coyly declines to translate. After recruiting a band from other buskers, they go into the studio to record.

行內代碼

一對```包括的文字將被渲染為代碼。

They impress Eamon, the jaded studio engineer, with their first song ("When Your Mind's Made Up"). On a break in the early morning, Girl finds a piano in an empty studio and plays Guy one of her own compositions ("`The Hill`"). 

They impress Eamon, the jaded studio engineer, with their first song ("When Your Mind's Made Up"). On a break in the early morning, Girl finds a piano in an empty studio and plays Guy one of her own compositions ("The Hill").

刪除線

通過一對~~為被其包括的文字添加刪除線。

After the ~~all-night~~ session wraps up, they walk home. Before they part ways, Girl reveals that she spoke to her husband and he is coming to live with her in Dublin.

After the all-night session wraps up, they walk home. Before they part ways, Girl reveals that she spoke to her husband and he is coming to live with her in Dublin.

Emoji

一對:包括的簡碼將被解釋為絵文字。在這里能夠找到可用的簡碼。

:man: persuades :woman: to spend his last night in Dublin with him, but :woman: stands him up and :man: cannot find her to say goodbye before his :airplane:. :man: plays the demo for his :older_man:, who gives him :dollar: to help him get settled in London.

👨 persuades 👩 to spend his last night in Dublin with him, but 👩 stands him up and 👨 cannot find her to say goodbye before his ✈️. 👨 plays the demo for his 👴, who gives him 💵 to help him get settled in London.

行內數學公式

  • 注意:數學公式不是GFM的一部分。

一對$包括的內容將被渲染為公式,它接受 Tex/LaTeX 指令。若這個功能由MathJax提供,在這里能夠找到可用的指令。

What if there is a $\LaTeX$ formula about music?

What if there is a \(\LaTeX\) formula about music?

轉義字符

通過\對緊隨其后的一個標點符號進行轉義,被轉義的字符將不再被Markdown解釋。若跟隨的字符不可被轉義,則\自身將被渲染。

  • 可被轉義的字符:ASCII中的任意標點符號;特別的,換行符將被轉義為一個硬回車。
  • 禁用轉義的區域:代碼塊行內代碼鏈接地址HTML
Before leaving for the airport\, Guy buys Girl a piano and makes arrangements for its delivery\, then calls his ex\-girlfriend\, who is happy about his imminent arrival\. \
Girl reunites with her husband in Dublin and plays the piano in their home\. 

Before leaving for the airport, Guy buys Girl a piano and makes arrangements for its delivery, then calls his ex-girlfriend, who is happy about his imminent arrival.
Girl reunites with her husband in Dublin and plays the piano in their home.

HTML

GFM支持在源文件中直接包含HTML代碼,其中的字符不再被Markdown解釋。

<object type="image/svg+xml" data="https://blog-static.cnblogs.com/files/yuiko/claw.svg" style="background-color:pink;padding:16px;width:64px;height:64px;"></object>


  1. "Falling Slowly", available at NeteaseMusic. ↩︎


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM