Markdown

Markdown

Hugo 支持 Markdown 来书写内容,创建列表等。本页将向你展示一些最常见的 Markdown 语法示例。

Markdown 示例

文本样式

StyleSyntaxExampleOutput
Bold**bold text****bold text**bold text
Italic*italicized text*`italicized textitalicized text
Strikethrough~~strikethrough text~~~~strikethrough text~~strikethrough text
Subscript<sub></sub>This is a <sub>subscript</sub> textThis is a subscript text
Superscript<sup></sup>This is a <sup>superscript</sup> textThis is a superscript text

引用

带角标的块引用:

Don’t communicate by sharing memory, share memory by communicating.
Rob Pike1

Markdown
> Don't communicate by sharing memory, share memory by communicating.<br>
> — <cite>Rob Pike[^1]</cite>

[^1]: The above quote is excerpted from Rob Pike's [talk](https://www.youtube.com/watch?v=PAAkCSZUG1c) during Gopherfest, November 18, 2015.

表格

表格并非核心 Markdown 规范,但 Hugo 支持开箱即用的表格:

NameAge
Bob27
Alice23
Markdown
|   Name | Age  |
|--------|------|
|    Bob | 27   |
|  Alice | 23   |

Markdown 表格中的内联

ItalicsBoldCode
italicsboldcode
Markdown
| Italics   | Bold     | Code   |
| --------  | -------- | ------ |
| *italics* | **bold** | `code` |

代码块

列表

有序列表

  1. First item
  2. Second item
  3. Third item
Markdown
1. First item
2. Second item
3. Third item

无序列表

  • List item
  • Another item
  • And another item
Markdown
* List item
* Another item
* And another item

嵌套列表

  • Fruit
    • Apple
    • Orange
    • Banana
  • Dairy
    • Milk
    • Cheese
Markdown
* Fruit
  * Apple
  * Orange
  * Banana
* Dairy
  * Milk
  * Cheese

图片

landscape

Markdown
![landscape](https://picsum.photos/800/600)

带有标题:

landscape
Unsplash Landscape

Markdown
![landscape](https://picsum.photos/800/600 "Unsplash Landscape")

配置

Hugo 使用 Goldmark 解析 Markdown。 Markdown 渲染可以在 hugo.yaml 中的 markup.goldmark 中配置。以下是Hextra的默认配置:

hugo.yaml
markup:
  goldmark:
    renderer:
      unsafe: true
  highlight:
    noClasses: false

如需了解更多选项,转至 Configure Markup

参考资料


  1. The above quote is excerpted from Rob Pike’s talk during Gopherfest, November 18, 2015. ↩︎

最后更新于