# Hugo/FixIt语法参考 此文章系Hugo以及FixIt主题所支持的Markdown语法规则参考及演示 ## 0 摘要 使用如下代码进行手动摘要分割: ```markdown ``` ## 1 标题 从 `h2` 到 `h6` 的标题在每个级别上都加上一个 `#`: ```markdown ## h2 标题 ### h3 标题 #### h4 标题 ##### h5 标题 ###### h6 标题 ``` 输出的 HTML 看起来像这样: ```html

h2 标题

h3 标题

h4 标题

h5 标题
h6 标题
``` {{< admonition note "标题 ID" >}} 要添加自定义标题 ID, 请在与标题相同的行中将自定义 ID 放在花括号中: ```markdown ### 一个很棒的标题 {#custom-id} ``` 输出的 HTML 看起来像这样: ```html

一个很棒的标题

``` {{< /admonition >}} ## 2 注释 注释是和 HTML 兼容的: ```html ``` **不能**看到以下的注释: ## 3 水平线 HTML 中的 `
` 标签是用来在段落元素之间创建一个 "专题间隔" 的. 使用 Markdown, 你可以用以下方式创建一个 `
` 标签: * `___`: 三个连续的下划线 * `---`: 三个连续的破折号 * `***`: 三个连续的星号 呈现的输出效果如下: ___ --- *** ## 4 段落 按照纯文本的方式书写段落, 纯文本在呈现的 HTML 中将用 `

`/`

` 标签包裹. 如下段落: ```markdown Lorem ipsum dolor sit amet, graecis denique ei vel, at duo primis mandamus. Et legere ocurreret pri, animal tacimates complectitur ad cum. Cu eum inermis inimicus efficiendi. Labore officiis his ex, soluta officiis concludaturque ei qui, vide sensibus vim ad. ``` 输出的 HTML 看起来像这样: ```html

Lorem ipsum dolor sit amet, graecis denique ei vel, at duo primis mandamus. Et legere ocurreret pri, animal tacimates complectitur ad cum. Cu eum inermis inimicus efficiendi. Labore officiis his ex, soluta officiis concludaturque ei qui, vide sensibus vim ad.

``` 可以使用一个空白行进行**换行**. ## 5 内联 HTML 元素 如果你需要某个 HTML 标签 (带有一个类), 则可以简单地像这样使用: ```html Markdown 格式的段落.
这是 HTML
Markdown 格式的段落. ``` ## 6 强调 ### 加粗 用于强调带有较粗字体的文本片段. 以下文本片段会被 **渲染为粗体**. ```markdown **渲染为粗体** __渲染为粗体__ ``` 输出的 HTML 看起来像这样: ```html 渲染为粗体 ``` ### 斜体 用于强调带有斜体的文本片段. 以下文本片段被 _渲染为斜体_. ```markdown *渲染为斜体* _渲染为斜体_ ``` 输出的 HTML 看起来像这样: ```html 渲染为斜体 ``` ### 删除线 按照 [[GFM]^(GitHub flavored Markdown)](https://github.github.com/gfm/) 你可以使用删除线. ```markdown ~~这段文本带有删除线.~~ ``` 呈现的输出效果如下: ~~这段文本带有删除线.~~ 输出的 HTML 看起来像这样: ```html 这段文本带有删除线. ``` ### 组合 加粗, 斜体, 和删除线可以 组合使用. ```markdown ***加粗和斜体*** ~~**删除线和加粗**~~ ~~*删除线和斜体*~~ ~~***加粗, 斜体和删除线***~~ ``` 呈现的输出效果如下: ***加粗和斜体*** ~~**删除线和加粗**~~ ~~*删除线和斜体*~~ ~~***加粗, 斜体和删除线***~~ 输出的 HTML 看起来像这样: ```html 加粗和斜体 删除线和加粗 删除线和斜体 加粗, 斜体和删除线 ``` ## 7 引用 用于在文档中引用其他来源的内容块. 在要引用的任何文本之前添加 `>`: ```markdown > **Fusion Drive** combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined. ``` 呈现的输出效果如下: > **Fusion Drive** combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined. 输出的 HTML 看起来像这样: ```html

Fusion Drive combines a hard drive with a flash storage (solid-state drive) and presents it as a single logical volume with the space of both drives combined.

``` 引用也可以嵌套: ```markdown > Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi. >> Sed adipiscing elit vitae augue consectetur a gravida nunc vehicula. Donec auctor odio non est accumsan facilisis. Aliquam id turpis in dolor tincidunt mollis ac eu diam. ``` 呈现的输出效果如下: > Donec massa lacus, ultricies a ullamcorper in, fermentum sed augue. Nunc augue augue, aliquam non hendrerit ac, commodo vel nisi. >> Sed adipiscing elit vitae augue consectetur a gravida nunc vehicula. Donec auctor odio non est accumsan facilisis. Aliquam id turpis in dolor tincidunt mollis ac eu diam. ## 8 列表 ### 无序列表 一系列项的列表, 其中项的顺序没有明显关系. 你可以使用以下任何符号来表示无序列表中的项: ```markdown * 一项内容 - 一项内容 + 一项内容 ``` 例如: ```markdown * Lorem ipsum dolor sit amet * Consectetur adipiscing elit * Integer molestie lorem at massa * Facilisis in pretium nisl aliquet * Nulla volutpat aliquam velit * Phasellus iaculis neque * Purus sodales ultricies * Vestibulum laoreet porttitor sem * Ac tristique libero volutpat at * Faucibus porta lacus fringilla vel * Aenean sit amet erat nunc * Eget porttitor lorem ``` 呈现的输出效果如下: * Lorem ipsum dolor sit amet * Consectetur adipiscing elit * Integer molestie lorem at massa * Facilisis in pretium nisl aliquet * Nulla volutpat aliquam velit * Phasellus iaculis neque * Purus sodales ultricies * Vestibulum laoreet porttitor sem * Ac tristique libero volutpat at * Faucibus porta lacus fringilla vel * Aenean sit amet erat nunc * Eget porttitor lorem 输出的 HTML 看起来像这样: ```html ``` ### 有序列表 一系列项的列表, 其中项的顺序确实很重要. ```markdown 1. Lorem ipsum dolor sit amet 2. Consectetur adipiscing elit 3. Integer molestie lorem at massa 4. Facilisis in pretium nisl aliquet 5. Nulla volutpat aliquam velit 6. Faucibus porta lacus fringilla vel 7. Aenean sit amet erat nunc 8. Eget porttitor lorem ``` 呈现的输出效果如下: 1. Lorem ipsum dolor sit amet 2. Consectetur adipiscing elit 3. Integer molestie lorem at massa 4. Facilisis in pretium nisl aliquet 5. Nulla volutpat aliquam velit 6. Faucibus porta lacus fringilla vel 7. Aenean sit amet erat nunc 8. Eget porttitor lorem 输出的 HTML 看起来像这样: ```html
  1. Lorem ipsum dolor sit amet
  2. Consectetur adipiscing elit
  3. Integer molestie lorem at massa
  4. Facilisis in pretium nisl aliquet
  5. Nulla volutpat aliquam velit
  6. Faucibus porta lacus fringilla vel
  7. Aenean sit amet erat nunc
  8. Eget porttitor lorem
``` {{< admonition tip >}} 如果你对每一项使用 `1.`, Markdown 将自动为每一项编号. 例如: ```markdown 1. Lorem ipsum dolor sit amet 1. Consectetur adipiscing elit 1. Integer molestie lorem at massa 1. Facilisis in pretium nisl aliquet 1. Nulla volutpat aliquam velit 1. Faucibus porta lacus fringilla vel 1. Aenean sit amet erat nunc 1. Eget porttitor lorem ``` 呈现的输出效果如下: 1. Lorem ipsum dolor sit amet 1. Consectetur adipiscing elit 1. Integer molestie lorem at massa 1. Facilisis in pretium nisl aliquet 1. Nulla volutpat aliquam velit 1. Faucibus porta lacus fringilla vel 1. Aenean sit amet erat nunc 1. Eget porttitor lorem {{< /admonition >}} ### 任务列表 任务列表使你可以创建带有复选框的列表. 要创建任务列表, 请在任务列表项之前添加破折号 (`-`) 和带有空格的方括号 (`[ ]`). 要选择一个复选框,请在方括号之间添加 x (`[x]`). ```markdown - [x] Write the press release - [ ] Update the website - [ ] Contact the media ``` 呈现的输出效果如下: - [x] Write the press release - [ ] Update the website - [ ] Contact the media ## 9 代码 ### 行内代码 用 ` 包装行内代码段. ```markdown 在这个例子中, `
` 会被包裹成 **代码**. ``` 呈现的输出效果如下: 在这个例子中, `
` 会被包裹成 **代码**. 输出的 HTML 看起来像这样: ```html

在这个例子中, <section></section> 会被包裹成 代码.

``` ### 缩进代码 将几行代码缩进至少四个空格,例如: ```markdown // Some comments line 1 of code line 2 of code line 3 of code ``` 呈现的输出效果如下: // Some comments line 1 of code line 2 of code line 3 of code 输出的 HTML 看起来像这样: ```html
  
    // Some comments
    line 1 of code
    line 2 of code
    line 3 of code
  
``` ### 围栏代码块 使用 "围栏" ``` 来生成一段带有语言属性的代码块. {{< highlight markdown >}} ```markdown Sample text here... ``` {{< / highlight >}} 输出的 HTML 看起来像这样: ```html
  Sample text here...
``` ### 语法高亮 [GFM]^(GitHub Flavored Markdown) 也支持语法高亮. 要激活它,只需在第一个代码 "围栏" 之后直接添加你要使用的语言的文件扩展名, ```js, 语法高亮显示将自动应用于渲染的 HTML 中. 例如, 在以下 JavaScript 代码中应用语法高亮: {{< highlight markdown >}} ```js grunt.initConfig({ assemble: { options: { assets: 'docs/assets', data: 'src/data/*.{json,yml}', helpers: 'src/custom-helpers.js', partials: ['src/partials/**/*.{hbs,md}'] }, pages: { options: { layout: 'default.hbs' }, files: { './': ['src/templates/pages/index.hbs'] } } } }; ``` {{< / highlight >}} 呈现的输出效果如下: ```js grunt.initConfig({ assemble: { options: { assets: 'docs/assets', data: 'src/data/*.{json,yml}', helpers: 'src/custom-helpers.js', partials: ['src/partials/**/*.{hbs,md}'] }, pages: { options: { layout: 'default.hbs' }, files: { './': ['src/templates/pages/index.hbs'] } } } }; ``` {{< admonition >}} **Hugo** 文档中的 [语法高亮页面](https://gohugo.io/content-management/syntax-highlighting/) 介绍了有关语法高亮的更多信息, 包括语法高亮的 shortcode. {{< /admonition >}} ## 10 表格 通过在每个单元格之间添加竖线作为分隔线, 并在标题下添加一行破折号 (也由竖线分隔) 来创建表格. 注意, 竖线不需要垂直对齐. ```markdown | Option | Description | | ------ | ----------- | | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | ``` 呈现的输出效果如下: | Option | Description | | ------ | ----------- | | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | 输出的 HTML 看起来像这样: ```html
Option Description
data path to data files to supply the data that will be passed into templates.
engine engine to be used for processing templates. Handlebars is the default.
ext extension to be used for dest files.
``` {{< admonition note "文本右对齐或居中对齐" >}} 在任何标题下方的破折号右侧添加冒号将使该列的文本右对齐. 在任何标题下方的破折号两边添加冒号将使该列的对齐文本居中. ```markdown | Option | Description | |:------:| -----------:| | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | ``` 呈现的输出效果如下: | Option | Description | |:------:| -----------:| | data | path to data files to supply the data that will be passed into templates. | | engine | engine to be used for processing templates. Handlebars is the default. | | ext | extension to be used for dest files. | {{< /admonition >}} ## 11 链接 {#links} ### 基本链接 ```markdown [Assemble](https://assemble.io) ``` 呈现的输出效果如下 (将鼠标悬停在链接上,没有提示): [Assemble](https://assemble.io) 输出的 HTML 看起来像这样: ```html https://assemble.io contact@revolunet.com Assemble ``` ### 添加一个标题 ```markdown [Upstage](https://github.com/upstage/ "Visit Upstage!") ``` 呈现的输出效果如下 (将鼠标悬停在链接上,会有一行提示): [Upstage](https://github.com/upstage/ "Visit Upstage!") 输出的 HTML 看起来像这样: ```html Upstage ``` ### 定位标记 定位标记使你可以跳至同一页面上的指定锚点. 例如, 每个章节: ```markdown ## Table of Contents * [Chapter 1](#chapter-1) * [Chapter 2](#chapter-2) * [Chapter 3](#chapter-3) ``` 将跳转到这些部分: ```markdown ## Chapter 1 Content for chapter one. ## Chapter 2 Content for chapter one. ## Chapter 3 Content for chapter one. ``` {{< admonition >}} 定位标记的位置几乎是任意的. 因为它们并不引人注目, 所以它们通常被放在同一行了. {{< /admonition >}} ## 12 脚注 脚注使你可以添加注释和参考, 而不会使文档正文混乱. 当你创建脚注时, 会在添加脚注引用的位置出现带有链接的上标编号. 读者可以单击链接以跳至页面底部的脚注内容. 要创建脚注引用, 请在方括号中添加插入符号和标识符 (`[^1]`). 标识符可以是数字或单词, 但不能包含空格或制表符. 标识符仅将脚注引用与脚注本身相关联 - 在脚注输出中, 脚注按顺序编号. 在中括号内使用插入符号和数字以及用冒号和文本来添加脚注内容 (`[^1]:这是一段脚注`). 你不一定要在文档末尾添加脚注. 可以将它们放在除列表, 引用和表格等元素之外的任何位置. ```markdown 这是一个数字脚注[^1]. 这是一个带标签的脚注[^label] [^1]: 这是一个数字脚注 [^label]: 这是一个带标签的脚注 ``` 这是一个数字脚注[^1]. 这是一个带标签的脚注[^label] [^1]: 这是一个数字脚注 [^label]: 这是一个带标签的脚注 ## 13 图片 图片的语法与链接相似, 但包含一个在前面的感叹号. ```markdown ![Minion](https://octodex.github.com/images/minion.png) ``` ![Minion](https://octodex.github.com/images/minion.png) 或者: ```markdown ![Alt text](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat") ``` ![Alt text](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat") 像链接一样, 图片也具有脚注样式的语法: ```markdown ![Alt text][id] ``` ![Alt text][id] 稍后在文档中提供参考内容, 用来定义 URL 的位置: ```markdown [id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" ``` [id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat" {{< admonition tip >}} **FixIt** 主题提供了一个包含更多功能的 [图片的 shortcode](../theme-documentation-extended-shortcodes#image). {{< /admonition >}} ## 14 数学公式 {#formula} **FixIt** 基于 [$\KaTeX$][katex] 或 [$\text{MathJax}$][mathjax] 提供数学公式的支持,默认引擎为 $\KaTeX$。 你可以在 [主题配置][theme-config] 中修改数学公式自动渲染的相关配置: ```toml {title="hugo.toml"} [markup] [markup.goldmark] [markup.goldmark.extensions] [markup.goldmark.extensions.passthrough] enable = true [markup.goldmark.extensions.passthrough.delimiters] block = [ [ '\[', '\]' ], [ '$$', '$$' ] ] inline = [ [ '\(', '\)' ], [ '$', '$' ] ] [params] [params.page] [params.page.math] enable = true # mathematical formulas rendering engines, optional values: ["katex", "mathjax"] type = "katex" # KaTeX server-side rendering (https://katex.org) # KaTeX partial config: https://gohugo.io/functions/transform/tomath/#options [params.page.math.katex] # KaTeX extension copy-tex copyTex = true throwOnError = false errorColor = "#ff4949" # custom macros map # syntax: = [params.page.math.katex.macros] # "\\f" = "#1f(#2)" # usage: $\f{a}{b}$ # MathJax server-side rendering (https://www.mathjax.org) # MathJax config: https://docs.mathjax.org/en/latest/options/index.html [params.page.math.mathjax] cdn = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" [params.page.math.mathjax.packages] # "[+]" = ['configmacros'] # custom macros map # syntax: = [params.page.math.mathjax.macros] # "bold" = ["{\\bf #1}", 1] # usage: $\bold{math}$ [params.page.math.mathjax.loader] load = [ "ui/safe" ] [params.page.math.mathjax.loader.paths] # custom = "https://cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.1/build/" # more loader config e.g source, dependencies, provides etc. [params.page.math.mathjax.options] enableMenu = true # HTML tags that won't be searched for math skipHtmlTags = [ "script", "noscript", "style", "textarea", "pre", "code", "math", "select", "option", "mjx-container" ] # class that marks tags not to search ignoreHtmlClass = "mathjax_ignore" # HTML tags that can appear within math [params.page.math.mathjax.options.includeHtmlTags] # "#comment" = "" # br = "\n" # wbr = "" ``` ### KaTeX $\KaTeX$ 通过 Hugo 的 [`transform.ToMath`][tomath] 函数在 **服务器端渲染**,所以客户端加载 **速度更快**。 > [!tip] > 有一份 [$\KaTeX$ 中支持的 $\TeX$ 函数](https://katex.org/docs/supported.html) 清单。 #### 行内公式 默认的行内公式分割符有: - `$ ... $` - `\( ... \)` 例如: ```tex $c = \pm\sqrt{a^2 + b^2}$ 和 \(f(x)=\int_{-\infty}^{\infty} \hat{f}(\xi) e^{2 \pi i \xi x} d \xi\) ``` 呈现的输出效果如下: $c = \pm\sqrt{a^2 + b^2}$ 和 \(f(x)=\int_{-\infty}^{\infty} \hat{f}(\xi) e^{2 \pi i \xi x} d \xi\) #### 公式块 默认的公式块分割符有: - `$$ ... $$` - `\[ ... \]` 例如: ```tex $$ c = \pm\sqrt{a^2 + b^2} $$ \[f(x)=\int_{-\infty}^{\infty} \hat{f}(\xi) e^{2 \pi i \xi x} d \xi\] $$ \begin{equation*} \rho \frac{\mathrm{D} \mathbf{v}}{\mathrm{D} t}=\nabla \cdot \mathbb{P}+\rho \mathbf{f} \end{equation*} $$ $$ \begin{equation} \mathbf{E}=\sum_{i} \mathbf{E}\_{i}=\mathbf{E}\_{1}+\mathbf{E}\_{2}+\mathbf{E}_{3}+\cdots \end{equation} $$ $$ \begin{align} a&=b+c \\ d+e&=f \end{align} $$ $$ \begin{alignat}{2} 10&x+&3&y = 2 \\ 3&x+&13&y = 4 \end{alignat} $$ $$ \begin{gather} a=b \\ e=b+c \end{gather} $$ $$ \begin{CD} A @>a>> B \\ @VbVV @AAcA \\ C @= D \end{CD} $$ ``` 呈现的输出效果如下: $$ c = \pm\sqrt{a^2 + b^2} $$ \[f(x)=\int_{-\infty}^{\infty} \hat{f}(\xi) e^{2 \pi i \xi x} d \xi\] $$ \begin{equation*} \rho \frac{\mathrm{D} \mathbf{v}}{\mathrm{D} t}=\nabla \cdot \mathbb{P}+\rho \mathbf{f} \end{equation*} $$ $$ \begin{equation} \mathbf{E}=\sum_{i} \mathbf{E}\_{i}=\mathbf{E}\_{1}+\mathbf{E}\_{2}+\mathbf{E}_{3}+\cdots \end{equation} $$ $$ \begin{align} a&=b+c \\ d+e&=f \end{align} $$ $$ \begin{alignat}{2} 10&x+&3&y = 2 \\ 3&x+&13&y = 4 \end{alignat} $$ $$ \begin{gather} a=b \\ e=b+c \end{gather} $$ $$ \begin{CD} A @>a>> B \\ @VbVV @AAcA \\ C @= D \end{CD} $$ #### 复制公式 {#copy-tex} **[Copy-tex][copy-tex]** 是一个 **$\KaTeX$** 的插件。 通过这个扩展,在选择并复制 $\KaTeX$ 渲染的公式时,会将其 $\LaTeX$ 源代码复制到剪贴板。 在你的 [主题配置][theme-config] 中的 `[params.page.math.katex]` 下面设置属性 `copyTex = true` 来启用 Copy-tex。 选择并复制上一节中渲染的公式,可以发现复制的内容为 $\LaTeX$ 源代码。 #### 化学方程式 {#chemistry} **[mhchem][mhchem]** 是一个 **$\KaTeX$** 的插件,提供了 `\ce` 和 `\pu` 函数。 通过这个扩展,你可以在文章中轻松编写漂亮的化学方程式。 ```markdown $$ \ce{CO2 + C -> 2 CO} $$ $$ \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} $$ $$C_p[\ce{H2O(l)}] = \pu{75.3 J // mol K}$$ ``` 呈现的输出效果如下: $$ \ce{CO2 + C -> 2 CO} $$ $$ \ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} $$ $$C_p[\ce{H2O(l)}] = \pu{75.3 J // mol K}$$ #### 自定义宏 {#custom-macros} 你可以在你的 [主题配置][theme-config] 中的 `[params.page.math.katex.macros]` 下面添加自定义宏。 例如: ```toml [params.page.math.katex.macros] "\\f" = "#1f(#2)" # usage: $\f{a}{b}$ ``` 然后在文章中使用: ```tex $$ \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi $$ ``` 呈现的输出效果如下: $$ \f\relax{x} = \int_{-\infty}^\infty \f\hat\xi\,e^{2 \pi i \xi x} \,d\xi $$ ## 15 字符修饰 **FixIt** 主题支持多种 **字符修饰** Markdown 扩展语法: ```markdown [Hugo]{?^}(一个开源的静态网站生成工具) [99]{?/}[100] GIF是一种位图图片格式。 H2O Xn + Yn = Zn 按下CTRL+ALT+Delete以访问任务管理器。 大多数口腔癌都是由于不良的生活习惯导致的。 ``` 呈现的输出效果如下: [Hugo]^(一个开源的静态网站生成工具) [90]/[100] GIF是一种位图图片格式。 H2O Xn + Yn = Zn 按下CTRL+ALT+Delete以访问任务管理器。 大多数口腔癌都是由于不良的生活习惯导致的。 ## 16 转义字符 {#escape-character} 在某些特殊情况下,文章内容会与 Markdown 的基本或者扩展语法冲突, 并且无法避免. 转义字符语法可以帮助你渲染出想要的内容: ```markdown {{??}X} -> X ``` 例如, 两个 `:` 会启用 emoji 语法. 但有时候这不是你想要的结果. 可以像这样使用转义字符语法: ```markdown {{??}:}joy: ``` 呈现的输出效果如下: **{?:}joy{?:}** 而不是 **:joy:** 另一个例子是: ```markdown [link{{??}]}(#escape-character) ``` 呈现的输出效果如下: **[link{?]}(#escape-character)** 而不是 **[link](#escape-character)**. ## 17 内置shortcode ### 1 figure 一个 `figure` 示例: ```markdown {{}} ``` 呈现的输出效果如下: {{< figure src="https://octodex.github.com/images/minion.png" title="Lighthouse (figure)" >}} 输出的 HTML 看起来像这样: ```html

Lighthouse (figure)

``` ### 2 gist 一个 `gist` 示例: ```markdown {{}} ``` 呈现的输出效果如下: {{< gist spf13 7896402 >}} 输出的 HTML 看起来像这样: ```html ``` ### 3 highlight 一个 `highlight` 示例: ```markdown {{}}

{{ .Title }}

{{ range .Pages }} {{ .Render "summary"}} {{ end }}
{{}} ``` 呈现的输出效果如下: {{< highlight html >}}

{{ .Title }}

{{ range .Pages }} {{ .Render "summary"}} {{ end }}
{{< /highlight >}} ## 18 扩展shortcode ### 1 style `style` shortcode 用来在你的文章中插入自定义样式,它有两个位置参数. 第一个参数是自定义样式的内容. 它支持 [SASS](https://sass-lang.com/documentation/style-rules/declarations#nesting) 中的嵌套语法,并且 `&` 指代这个父元素. 第二个参数是包裹你要更改样式的内容的 HTML 标签, 默认值是 `div`. 一个 `style` 示例: ```markdown {{}} This is a **right-aligned** paragraph. {{}} ``` 呈现的输出效果如下: {{< style "text-align:right; strong{color:#00b1ff;}" >}} This is a **right-aligned** paragraph. {{< /style >}} ### 2 link `link` shortcode 是 Markdown 链接语法的替代,可以提供一些其它的功能并且可以在代码块中使用。 `link` shortcode 有以下命名参数: * **href** *[必需]* (**第一个**位置参数) 链接的目标. * **content** *[可选]* (**第二个**位置参数) 链接的内容, 默认值是 **href** 参数的值. *支持 Markdown 或者 HTML 格式.* * **title** *[可选]* (**第三个**位置参数) HTML `a` 标签 的 `title` 属性, 当悬停在链接上会显示的提示. * **rel** *[可选]* HTML `a` 标签 的 `rel` 补充属性. * **class** *[可选]* HTML `a` 标签 的 `class` 属性. 一个 `link` 示例: ```markdown {{}} 或者 {{}} {{}} 或者 {{}} {{}} 或者 {{}} ``` 呈现的输出效果如下: * {{< link "https://assemble.io" >}} * {{< link "mailto:contact@revolunet.com" >}} * {{< link "https://assemble.io" Assemble >}} 一个带有标题的 `link` 示例: ```markdown {{}} 或者 {{}} ``` 呈现的输出效果如下 (将鼠标悬停在链接上,会有一行提示): {{< link "https://github.com/upstage/" Upstage "Visit Upstage!" >}} ### 3 image `image` shortcode 是 `figure` shortcode的替代,`image` shortcode 可以充分利用 [lazysizes](https://github.com/aFarkas/lazysizes) 和 [lightGallery](https://github.com/sachinchoolur/lightgallery) 两个依赖库. `image` shortcode 有以下命名参数: * **src** *[必需]* (**第一个**位置参数) 图片的 URL. * **alt** *[可选]* (**第二个**位置参数) 图片无法显示时的替代文本, 默认值是 **src** 参数的值. *支持 Markdown 或者 HTML 格式.* * **caption** *[可选]* (**第三个**位置参数) 图片标题. *支持 Markdown 或者 HTML 格式.* * **title** *[可选]* 当悬停在图片上会显示的提示. * **class** *[可选]* HTML `figure` 标签的 `class` 属性. * **src_s** *[可选]* 图片缩略图的 URL, 用在画廊模式中, 默认值是 **src** 参数的值. * **src_l** *[可选]* 高清图片的 URL, 用在画廊模式中, 默认值是 **src** 参数的值. * **height** *[可选]* 图片的 `height` 属性. * **width** *[可选]* 图片的 `width` 属性. * **linked** *[可选]* 图片是否需要被链接, 默认值是 `true`. * **rel** *[可选]* HTML `a` 标签 的 `rel` 补充属性, 仅在 **linked** 属性设置成 `true` 时有效. 一个 `image` 示例: ```markdown {{}} ``` ### 4 admonition `admonition` shortcode 支持 **12** 种 帮助你在页面中插入提示的横幅. *支持 Markdown 或者 HTML 格式.* {{< admonition >}} 一个 **注意** 横幅 {{< /admonition >}} {{< admonition abstract >}} 一个 **摘要** 横幅 {{< /admonition >}} {{< admonition info >}} 一个 **信息** 横幅 {{< /admonition >}} {{< admonition tip >}} 一个 **技巧** 横幅 {{< /admonition >}} {{< admonition success >}} 一个 **成功** 横幅 {{< /admonition >}} {{< admonition question >}} 一个 **问题** 横幅 {{< /admonition >}} {{< admonition warning >}} 一个 **警告** 横幅 {{< /admonition >}} {{< admonition failure >}} 一个 **失败** 横幅 {{< /admonition >}} {{< admonition danger >}} 一个 **危险** 横幅 {{< /admonition >}} {{< admonition bug >}} 一个 **Bug** 横幅 {{< /admonition >}} {{< admonition example >}} 一个 **示例** 横幅 {{< /admonition >}} {{< admonition quote >}} 一个 **引用** 横幅 {{< /admonition >}} `admonition` shortcode 有以下命名参数: * **type** *[可选]* (**第一个**位置参数) `admonition` 横幅的类型, 默认值是 `note`. * **title** *[可选]* (**第二个**位置参数) `admonition` 横幅的标题, 默认值是 **type** 参数的值. * **open** *[可选]* (**第三个**位置参数) {{< version 0.2.0 changed >}} 横幅内容是否默认展开, 默认值是 `true`. 一个 `admonition` 示例: ```markdown {{}} 一个 **技巧** 横幅 {{}} 或者 {{}} 一个 **技巧** 横幅 {{}} ``` 呈现的输出效果如下: {{< admonition tip "This is a tip" false >}} 一个 **技巧** 横幅 {{< /admonition >}} ### 5 mermaid `mermaid` shortcode 使用 [Mermaid](https://mermaidjs.github.io/) 库提供绘制图表和流程图的功能。[mermaid](https://mermaidjs.github.io/) 是一个可以帮助你在文章中绘制图表和流程图的库, 类似 Markdown 的语法。只需将你的 mermaid 代码插入 `mermaid` shortcode 中即可。 一个 **流程图** `mermaid` 示例: ```markdown {{}} graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two] {{}} ``` 呈现的输出效果如下: {{< mermaid >}} graph LR; A[Hard edge] -->|Link text| B(Round edge) B --> C{Decision} C -->|One| D[Result one] C -->|Two| E[Result two] {{< /mermaid >}} ### 6 echarts echarts` shortcode 使用 [ECharts](https://echarts.apache.org/) 库提供数据可视化的功能。**ECharts** 是一个生成交互式数据可视化的库。 只需在 `echarts` shortcode 中以 `JSON`/`YAML`/`TOML`格式插入 ECharts 选项即可。 `echarts` shortcode 有以下命名参数: * **width** *[可选]* (**第一个**位置参数) {{< version 0.2.0 >}} 数据可视化的宽度, 默认值是 `100%`. * **height** *[可选]* (**第二个**位置参数) {{< version 0.2.0 >}} 数据可视化的高度, 默认值是 `30rem`. 一个 `JSON` 格式的 `echarts` 示例: ```json {{}} { "title": { "text": "折线统计图", "top": "2%", "left": "center" }, "tooltip": { "trigger": "axis" }, "legend": { "data": ["邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"], "top": "10%" }, "grid": { "left": "5%", "right": "5%", "bottom": "5%", "top": "20%", "containLabel": true }, "toolbox": { "feature": { "saveAsImage": { "title": "保存为图片" } } }, "xAxis": { "type": "category", "boundaryGap": false, "data": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] }, "yAxis": { "type": "value" }, "series": [ { "name": "邮件营销", "type": "line", "stack": "总量", "data": [120, 132, 101, 134, 90, 230, 210] }, { "name": "联盟广告", "type": "line", "stack": "总量", "data": [220, 182, 191, 234, 290, 330, 310] }, { "name": "视频广告", "type": "line", "stack": "总量", "data": [150, 232, 201, 154, 190, 330, 410] }, { "name": "直接访问", "type": "line", "stack": "总量", "data": [320, 332, 301, 334, 390, 330, 320] }, { "name": "搜索引擎", "type": "line", "stack": "总量", "data": [820, 932, 901, 934, 1290, 1330, 1320] } ] } {{}} ``` 呈现的输出效果如下: {{< echarts >}} { "title": { "text": "折线统计图", "top": "2%", "left": "center" }, "tooltip": { "trigger": "axis" }, "legend": { "data": ["邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"], "top": "10%" }, "grid": { "left": "5%", "right": "5%", "bottom": "5%", "top": "20%", "containLabel": true }, "toolbox": { "feature": { "saveAsImage": { "title": "保存为图片" } } }, "xAxis": { "type": "category", "boundaryGap": false, "data": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"] }, "yAxis": { "type": "value" }, "series": [ { "name": "邮件营销", "type": "line", "stack": "总量", "data": [120, 132, 101, 134, 90, 230, 210] }, { "name": "联盟广告", "type": "line", "stack": "总量", "data": [220, 182, 191, 234, 290, 330, 310] }, { "name": "视频广告", "type": "line", "stack": "总量", "data": [150, 232, 201, 154, 190, 330, 410] }, { "name": "直接访问", "type": "line", "stack": "总量", "data": [320, 332, 301, 334, 390, 330, 320] }, { "name": "搜索引擎", "type": "line", "stack": "总量", "data": [820, 932, 901, 934, 1290, 1330, 1320] } ] } {{< /echarts >}} ### 7 bilibili `bilibili` shortcode 提供了一个内嵌的用来播放 bilibili 视频的响应式播放器. 如果视频只有一个部分, 则仅需要视频的 BV `id`, 例如: ```code https://www.bilibili.com/video/BV1Sx411T7QQ ``` 一个 `bilibili` 示例: ```markdown {{}} 或者 {{}} ``` 呈现的输出效果如下: {{< bilibili id=BV1Sx411T7QQ >}} 如果视频包含多个部分, 则除了视频的 BV `id` 之外, 还需要 `p`, 默认值为 `1`, 例如: ```code https://www.bilibili.com/video/BV1TJ411C7An?p=3 ``` 一个带有 `p` 参数的 `bilibili` 示例: ```markdown {{}} 或者 {{}} ``` 呈现的输出效果如下: {{< bilibili id=BV1TJ411C7An p=3 >}} ### 8 script `script` shortcode 用来在你的文章中插入 **Javascript** 脚本. {{< admonition >}} 脚本内容可以保证在所有的第三方库加载之后按顺序执行. 所以你可以自由地使用第三方库. {{< /admonition >}} 一个 `script` 示例: ```markdown {{}} console.log('Hello FixIt!'); {{}} ``` 你可以在开发者工具的控制台中看到输出. {{< script >}} console.log('Hello FixIt!'); {{< /script >}} ### 9 raw `raw` shortcode 用来在你的文章中插入原始 **HTML** 内容. 一个 `raw` 示例: ```markdown 行内公式: {{}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{}} 公式块: {{}} \[ a=b+c \\ d+e=f \] {{}} 原始的带有 Markdown 语法的内容: {{}}**Hello**{{}} ``` 呈现的输出效果如下: 行内公式: {{< raw >}}\(\mathbf{E}=\sum_{i} \mathbf{E}_{i}=\mathbf{E}_{1}+\mathbf{E}_{2}+\mathbf{E}_{3}+\cdots\){{< /raw >}} 公式块: {{< raw>}} \[ a=b+c \\ d+e=f \] {{< /raw >}} 原始的带有 Markdown 语法的内容: {{< raw >}}**Hello**{{< /raw >}} --- > 作者: [Francis Fu](https://francisfu.com/) > URL: https://francisfu.com/posts/hugo%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2%E7%94%9F%E6%88%90%E5%99%A8%E6%8C%87%E5%8D%97/hugo-fixit%E8%AF%AD%E6%B3%95%E5%8F%82%E8%80%83/