學習如何使用 [Markdown](https://daringfireball.net/projects/markdown/) 為筆記套用基本格式。如需更進階的格式語法,請參閱[[進階格式語法]]。
## 段落
在 Markdown 中建立段落時,請使用**空白行**來分隔文字區塊。每個以空白行分隔的文字區塊會被視為獨立的段落。
```md
This is a paragraph.
This is another paragraph.
```
This is a paragraph.
This is another paragraph.
文字行之間的空白行會建立獨立的段落。這是 Markdown 中的預設行為。
> [!tip]- 多個空白
> 段落內及段落之間的多個相鄰空白,在[[檢視與編輯模式#閱讀檢視|閱讀檢視]]或 [[Obsidian Publish 介紹|Obsidian Publish]] 網站上顯示時會被合併為單一空白。
>
> ```md
> Multiple adjacent spaces
>
>
>
> and multiple newlines between paragraphs.
> ```
>
> > Multiple adjacent spaces
> >
> >
> >
> > and multiple newlines between paragraphs.
>
> 如果你想防止空白被合併或新增多個空白,可以使用 ` `(不換行空格)或 `<br>`(換行)HTML 標籤。
### 換行
在 Obsidian 中,按下 `Enter` 一次預設會在筆記中建立新的一行,但在渲染輸出中,這會被視為同一段落的*延續*,遵循典型的 Markdown 行為。若要在段落*內*插入換行而不開始新段落,你可以:
- 在按下 `Enter` 之前,在行尾新增**兩個空格**,或
- 使用快捷鍵 `Shift+Enter` 直接插入換行。
> [!question]- 為什麼按多次 `Enter` 不會在閱讀檢視中產生更多換行?
> 在 Markdown 中,單一 `Enter` 會被忽略,而連續按多次 `Enter` 只會產生一個新段落。此行為符合 Markdown 的軟換行規則,額外的空白行不會產生額外的換行或段落——它們會被合併為單一段落分隔。這是 Markdown 處理文字的預設方式,確保段落自然流動而不會出現意外的中斷。
Obsidian 包含一項**[[設定#精確的換行符號|精確的換行符號]]**設定,使 Obsidian 遵循標準 Markdown 規範來處理換行。
啟用此功能:
1. 開啟**[[設定]]**。
2. 前往**編輯器**分頁。
3. 啟用**精確的換行符號**。
在 Obsidian 中啟用**精確的換行符號**後,換行會依據行與行之間的分隔方式產生三種不同的行為:
**單次回車且無空格**:單一 `Enter` 且行尾無空格時,兩行在渲染時會合併為同一行。
```md
line one
line two
```
渲染為:
line one line two
**單次回車且行尾有兩個或更多空格**:如果在按 `Enter` 之前在第一行末尾新增兩個或更多空格,兩行仍屬於同一段落,但會以換行(HTML `<br>` 元素)分隔。在此範例中,我們用兩個底線代表空格。
```md
line three__
line four
```
渲染為:
line three<br>
line four
**雙次回車(無論行尾有無空格)**:按兩次(或更多次)`Enter` 會將行分隔為兩個獨立段落(HTML `<p>` 元素),無論你是否在第一行末尾新增空格。
```md
line five
line six
```
渲染為:
<p>line five</p>
<p>line six</p>
## 標題
若要建立標題,在標題文字前新增最多六個 `#` 符號。`#` 符號的數量決定標題的層級(如[[大綱]]中所示)。
```md
# This is a heading 1
## This is a heading 2
### This is a heading 3
#### This is a heading 4
##### This is a heading 5
###### This is a heading 6
```
%% These headings use HTML to avoid cluttering the Outline/Table of contents %%
<h1>這是標題 1</h1>
<h2>這是標題 2</h2>
<h3>這是標題 3</h3>
<h4>這是標題 4</h4>
<h5>這是標題 5</h5>
<h6>這是標題 6</h6>
## 粗體、斜體、反白
文字格式也可以使用[[編輯快捷鍵]]來套用。
| 樣式 | 語法 | 範例 | 輸出 |
|-|-|-|-|
| 粗體 | `** **` 或 `__ __` | `**Bold text**` | **Bold text** |
| 斜體 | `* *` 或 `_ _` | `*Italic text*` | *Italic text* |
| 刪除線 | `~~ ~~` | `~~Striked out text~~` | ~~Striked out text~~ |
| 反白 | `== ==` | `==Highlighted text==` | ==Highlighted text== |
| 粗體與巢狀斜體 | `** **` 和 `_ _` | `**Bold text and _nested italic_ text**` | **Bold text and _nested italic_ text** |
| 粗體與斜體 | `*** ***` 或 `___ ___` | `***Bold and italic text***` | ***Bold and italic text*** |
可以在格式符號前加上反斜線 `\` 來強制以純文字顯示。
\*\*This line will not be bold\*\*
```markdown
\*\*This line will not be bold\*\*
```
\**This line will be italic and show the asterisks*\*
```markdown
\**This line will be italic and show the asterisks*\*
```
## 內部連結
Obsidian 支援兩種筆記之間的[[內部連結]]格式:
- Wiki 連結:`[[Three laws of motion]]`
- Markdown:`[Three laws of motion](Three%20laws%20of%20motion.md)`
## 外部連結
若要連結到外部 URL,可以將連結文字用方括號(`[ ]`)包圍,然後將 URL 放在圓括號(`( )`)中來建立行內連結。
```md
[Obsidian Help](https://help.obsidian.md)
```
[Obsidian Help](https://help.obsidian.md)
你也可以透過連結到 [[Obsidian URI|Obsidian URI]] 來建立指向其他保管庫中檔案的外部連結。
```md
[Note](obsidian://open?vault=MainVault&file=Note.md)
```
### 跳脫連結中的空格
如果你的 URL 包含空格,必須將空格替換為 `%20` 來跳脫。
```md
[My Note](obsidian://open?vault=MainVault&file=My%20Note.md)
```
你也可以用角括號(`< >`)將 URL 包起來跳脫。
```md
[My Note](<obsidian://open?vault=MainVault&file=My Note.md>)
```
## 外部圖片
你可以透過在[[#外部連結|外部連結]]前加上 `!` 符號來新增外部 URL 的圖片。
```md

```

你可以在連結目標後新增 `|640x480` 來變更圖片尺寸,其中 640 是寬度,480 是高度。
```md

```
如果只指定寬度,圖片會依據原始比例縮放。例如:
```md

```
> [!tip]- 小技巧
> 如果你想從保管庫內新增圖片,也可以[[嵌入檔案#在筆記中嵌入圖片|在筆記中嵌入圖片]]。
## 引用
你可以在文字前加上 `>` 符號來引用文字。
```md
> Human beings face ever more complex and urgent problems, and their effectiveness in dealing with these problems is a matter that is critical to the stability and continued progress of society.
\- Doug Engelbart, 1961
```
> Human beings face ever more complex and urgent problems, and their effectiveness in dealing with these problems is a matter that is critical to the stability and continued progress of society.
\- Doug Engelbart, 1961
> [!tip]- 小技巧
> 你可以在引用的第一行加上 `[!info]`,將引用轉換為[[註標|標註塊]]。
## 清單
你可以在文字前加上 `-`、`*` 或 `+` 來建立無序列表。
```md
- First list item
- Second list item
- Third list item
```
- First list item
- Second list item
- Third list item
若要建立有序清單,每行以數字後接 `.` 或 `)` 符號開頭。
```md
1. First list item
2. Second list item
3. Third list item
```
1. First list item
2. Second list item
3. Third list item
```md
1) First list item
2) Second list item
3) Third list item
```
1) First list item
2) Second list item
3) Third list item
你可以使用 `Shift+Enter` 在有序清單中插入[[#換行|換行]],而不會改變編號。
```md
1. First list item
2. Second list item
3. Third list item
4. Fourth list item
5. Fifth list item
6. Sixth list item
```
### 待辦清單
若要建立待辦清單,每個清單項目以連字號和空格後接 `[ ]` 開頭。
```md
- [x] This is a completed task.
- [ ] This is an incomplete task.
```
- [x] This is a completed task.
- [ ] This is an incomplete task.
你可以在閱讀檢視中點選核取方塊來切換任務狀態。
> [!tip]- 小技巧
> 你可以在方括號內使用任何字元來標記為已完成。
>
> ```md
> - [x] Milk
> - [?] Eggs
> - [-] Eggs
> ```
>
> - [x] Milk
> - [?] Eggs
> - [-] Eggs
### 巢狀清單
你可以在任何類型的清單下巢狀任何類型的清單——有序、無序或待辦清單。
若要建立巢狀清單,請將一或多個清單項目縮排。你可以在巢狀結構中混合使用不同的清單類型:
```md
1. First list item
1. Ordered nested list item
2. Second list item
- Unordered nested list item
```
1. First list item
1. Ordered nested list item
2. Second list item
- Unordered nested list item
同樣地,你可以透過縮排一或多個清單項目來建立巢狀待辦清單:
```md
- [ ] Task item 1
- [ ] Subtask 1
- [ ] Task item 2
- [ ] Subtask 1
```
- [ ] Task item 1
- [ ] Subtask 1
- [ ] Task item 2
- [ ] Subtask 1
使用 `Tab` 或 `Shift+Tab` 來縮排或減少縮排已選取的清單項目,以便輕鬆整理。
## 水平橫線
你可以在單獨一行使用三個或更多星號 `***`、連字號 `---` 或底線 `___` 來新增水平橫線。你也可以用空格分隔符號。
```md
***
****
* * *
---
----
- - -
___
____
_ _ _
```
***
## 程式碼
你可以將程式碼格式化為行內或獨立區塊。
### 行內程式碼
你可以使用單一反引號在句子中格式化程式碼。
```md
Text inside `backticks` on a line will be formatted like code.
```
Text inside `backticks` on a line will be formatted like code.
如果你想在行內程式碼區塊中放入反引號,請用雙反引號包圍,如:inline ``code with a backtick ` inside``。
### 程式碼區塊
若要將程式碼格式化為區塊,請用三個或更多反引號或三個或更多波浪號包圍。
~~~
`````
cd ~/Desktop
`````
~~~
`````
~~~
cd ~/Desktop
~~~
`````
`````md
cd ~/Desktop
`````
你也可以使用 `Tab` 或 4 個空格縮排文字來建立程式碼區塊。
`````md
cd ~/Desktop
`````
你可以在第一組反引號後加上語言代碼,為程式碼區塊新增語法高亮。
~~~md
`````js
function fancyAlert(arg) {
if(arg) {
$.facebox({div:'#foo'})
}
}
`````
~~~
`````js
function fancyAlert(arg) {
if(arg) {
$.facebox({div:'#foo'})
}
}
`````
Obsidian 使用 Prism 進行語法高亮。更多資訊請參閱 [Supported languages](https://prismjs.com/#supported-languages)。
> [!info]+ PrismJS 與編輯檢視
> [[檢視與編輯模式#原始碼模式|原始碼模式]]和[[檢視與編輯模式#即時預覽|即時預覽]]不支援 PrismJS,語法高亮的渲染可能會有所不同。
#### 巢狀程式碼區塊
當你需要在另一個程式碼區塊內包含程式碼區塊時(例如記錄如何使用程式碼區塊),可以為外層程式碼區塊使用三個以上的反引號或波浪號。
若要巢狀程式碼區塊,外層區塊使用四個或更多反引號(或波浪號),內層區塊使用三個:
`````md
````md
Here's how to create a code block:
```js
console.log("Hello world")
```
````
`````
你也可以混合使用反引號和波浪號。這在處理會產生其他程式碼區塊的程式碼時特別有用:
`````md
````md
```dataviewjs
dv.paragraph(`
~~~mermaid
graph TD
A --> B
~~~
`)
```
````
`````
關鍵原則是外層程式碼區塊必須使用**更多**的圍欄字元(反引號或波浪號),或使用不同類型的圍欄字元。
## 腳註
你可以使用以下語法為筆記新增腳註[^footnote]:
[^footnote]: 這是一個腳註。
```md
This is a simple footnote[^1].
[^1]: This is the referenced text.
[^2]: Add 2 spaces at the start of each new line.
This lets you write footnotes that span multiple lines.
[^note]: Named footnotes still appear as numbers, but can make it easier to identify and link references.
```
你也可以在句子中使用行內腳註。請注意插入符號在方括號外面。
```md
You can also use inline footnotes. ^[This is an inline footnote.]
```
> [!note] 備註
> 行內腳註僅在閱讀檢視中有效,在即時預覽中無效。
## 註解
你可以用 `%%` 包圍文字來新增註解。註解僅在編輯檢視中可見。
```md
This is an %%inline%% comment.
%%
This is a block comment.
Block comments can span multiple lines.
%%
```
## 跳脫 Markdown 語法
在某些情況下,你可能需要在 Markdown 中顯示特殊字元,如 `*`、`_` 或 `#`,而不觸發其格式化功能。若要以字面方式顯示這些字元,請在前面加上反斜線(`\`)。
> [!example] 常見的跳脫字元
>
> - 星號:`\*`
> - 底線:`\_`
> - 井號:`\#`
> - 反引號:`` \` ``
> - 管道符號(用於表格):`\|`
> - 波浪號:`\~`
```md
\*This text will not be italicized\*.
```
\*This text will not be italicized\*.
在使用有序清單時,你可能需要跳脫數字後的句點以防止自動清單格式化。將反斜線(`\`)放在句點前,**而非**數字前。
```md
1\. This won't be a list item.
```
1\. This won't be a list item.
## 深入了解
若要了解更進階的格式語法,例如表格、圖表和數學運算式,請參閱[[進階格式語法]]。
若要了解 Obsidian 如何解析 Markdown,請參閱 [[Obsidian 風格 Markdown]]。