标记解析(Markup)
定义 Hugo 的 Markdown 解析器及其解析风格(包括:特殊字符解析规则、章节样式、代码高亮样式和表格样式)。
官方文档: https://gohugo.io/getting-started/configuration-markup/ (配置看这里)
所谓 “标记解析” 就是将 .md
文件中的各种特殊字符、特殊格式转换为 .html
文件形式。可以理解为渲染 .md
文件。
Goldmark —— 解析 markdown 标记
Hugo 默认使用 goldmark 解析 markdown 标记。
下面记录常用配置
unsafe
是否允许渲染 html 代码块。默认不渲染,替换为 <!--raw HTML omitted -->
代码块。
attribute
是否解析 {...}
额外语法。默认不解析,直接识别为普通文本。
extensions
https://github.com/yuin/goldmark/#extensions
Highlight —— 配置"代码高亮"风格
Hugo 使用 chroma 作为代码高亮解析器。
官方文档:
- https://gohugo.io/getting-started/configuration-markup/#highlight (配置)
- https://gohugo.io/content-management/syntax-highlighting/ (简码形式)
- https://gohugo.io/functions/transform/highlight/ (函数形式)
1# config/_default/markup.yml
2highlight:
3 anchorLineNos: false # 为每一行代码标注链接,如:"#hl-3-6"为第三个代码块中第六行
4 lineAnchors: "" # 链接前缀,默认"hl"
5 codeFences: true # 解析{...}扩展选项
6 guessSyntax: false # 猜测语法,关闭加速编译
7 hl_Lines: ""
8 hl_inline: false # 行高亮,一般不在这里设置,在codeFence中设置
9 lineNoStart: 1
10 lineNos: false # 行号
11 lineNumbersInTable: true # 可能有适配问题,旧版本关闭的
12 noClasses: true # 使用class标签,而不是内嵌的内联样式
13 noHl: false
14 style: monokai # 代码高亮主题,参考 https://xyproto.github.io/splash/docs/all.html
15 tabWidth: 4
Table of contents —— 右侧文章大纲配置
简称 “TOC”
1tableOfContents:
2 ordered: false # 是否添加序号,默认false
3 startLevel: 2 # 开始级别,默认1
4 endLevel: 4 # 结束级别,默认3
Last modified November 4, 2023: Correcting content dir (da1a055)