Debian Codegraph @

docs/content/en/configuration/markup.md

raw
1 ---
2 title: Configure markup
3 linkTitle: Markup
4 description: Configure markup.
5 categories: []
6 keywords: []
7 aliases: [/getting-started/configuration-markup/]
8 ---
9
10 ## Default handler
11
12 In its default configuration, Hugo uses [Goldmark][] to render Markdown to HTML.
13
14 {{< code-toggle file=hugo >}}
15 [markup]
16 defaultMarkdownHandler = 'goldmark'
17 {{< /code-toggle >}}
18
19 Files with ending with `.md`, `.mdown`, or `.markdown` are processed as Markdown, unless you've explicitly set a different format using the `markup` field in your front matter.
20
21 To use a different renderer for Markdown files, specify one of `asciidocext`, `org`, `pandoc`, or `rst` in your project configuration.
22
23 `defaultMarkdownHandler` | Renderer
24 :------------------------|:--------------------
25 `asciidocext` | [AsciiDoc][]
26 `goldmark` | [Goldmark][]
27 `org` | [Emacs Org Mode][]
28 `pandoc` | [Pandoc][]
29 `rst` | [reStructuredText][]
30
31 To use AsciiDoc, Pandoc, or reStructuredText you must install the relevant renderer and update your [security policy][].
32
33 > [!NOTE]
34 > Unless you need a unique capability provided by one of the alternative Markdown handlers, we strongly recommend that you use the default setting. Goldmark is fast, well maintained, conforms to the [CommonMark][] specification, and is compatible with [GitHub Flavored Markdown][] (GFM).
35
36 ## Goldmark
37
38 This is the default configuration for the Goldmark Markdown renderer:
39
40 {{< code-toggle config=markup.goldmark />}}
41
42 ### Extensions
43
44 The extensions below, excluding Extras and Passthrough, are enabled by default.
45
46 Extension | Documentation | Enabled
47 :----------------|:----------------------------------------------|:-----------------:
48 `cjk` | [Goldmark Extensions: CJK][] | :heavy_check_mark:
49 `definitionList` | [PHP Markdown Extra: Definition lists][] | :heavy_check_mark:
50 `extras` | [Hugo Goldmark Extensions: Extras][] | &nbsp;
51 `footnote` | [PHP Markdown Extra: Footnotes][] | :heavy_check_mark:
52 `linkify` | [GitHub Flavored Markdown: Autolinks][] | :heavy_check_mark:
53 `passthrough` | [Hugo Goldmark Extensions: Passthrough][] | &nbsp;
54 `strikethrough` | [GitHub Flavored Markdown: Strikethrough][] | :heavy_check_mark:
55 `table` | [GitHub Flavored Markdown: Tables][] | :heavy_check_mark:
56 `taskList` | [GitHub Flavored Markdown: Task list items][] | :heavy_check_mark:
57 `typographer` | [Goldmark Extensions: Typographer][] | :heavy_check_mark:
58
59 #### Extras
60
61 Enable [deleted text][], [inserted text][], [mark text][], [subscript][], and [superscript][] elements in Markdown.
62
63 Element | Markdown | Rendered
64 :-------------|:----------|:------------------
65 Deleted text | `~~foo~~` | `<del>foo</del>`
66 Inserted text | `++bar++` | `<ins>bar</ins>`
67 Mark text | `==baz==` | `<mark>baz</mark>`
68 Subscript | `H~2~O` | `H<sub>2</sub>O`
69 Superscript | `1^st^` | `1<sup>st</sup>`
70
71 To avoid a conflict[^1], if you enable the "subscript" feature of the Extras extension, you must disable the Strikethrough extension:
72
73 {{< code-toggle file=hugo >}}
74 [markup.goldmark.extensions]
75 strikethrough = false
76
77 [markup.goldmark.extensions.extras.subscript]
78 enable = true
79 {{< /code-toggle >}}
80
81 If you still need to show deleted text after disabling the Strikethrough extension, enable the "deleted text" feature of the Extras extension:
82
83 {{< code-toggle file=hugo >}}
84 [markup.goldmark.extensions]
85 strikethrough = false
86
87 [markup.goldmark.extensions.extras.delete]
88 enable = true
89 {{< /code-toggle >}}
90
91 With this configuration, to format text as deleted, wrap it with double-tildes.
92
93 #### Footnote
94
95 Enabled by default, the Footnote extension enables inclusion of footnotes in Markdown.
96
97 `enable`
98 : {{< new-in 0.151.0 />}}
99 : (`bool`) Whether to enable the Footnotes extension. Default is `true`.
100
101 `backlinkHTML`
102 : {{< new-in 0.151.0 />}}
103 : (`string`) The HTML to be displayed at the end of a footnote that links the user back to the corresponding reference in the main text. The default is &#x21a9;&#xfe0e; (a return arrow symbol).
104
105 `enableAutoIDPrefix`
106 : {{< new-in 0.151.0 />}}
107 : (`bool`) Whether to prepend a unique prefix to footnote IDs, preventing clashes when multiple documents are rendered together. This prefix is unique to each logical path, which means that the prefix is not unique across content dimensions such as language. Default is `false`.
108
109 #### Passthrough
110
111 Enable the Passthrough extension to include mathematical equations and expressions in Markdown using LaTeX markup. See [mathematics in Markdown][] for details.
112
113 #### Typographer
114
115 The Typographer extension replaces certain character combinations with HTML entities as specified below:
116
117 Markdown|Replaced by|Description
118 :--|:--|:--
119 `...`|`&hellip;`|horizontal ellipsis
120 `'`|`&rsquo;`|apostrophe
121 `--`|`&ndash;`|en dash
122 `---`|`&mdash;`|em dash
123 `«`|`&laquo;`|left angle quote
124 `“`|`&ldquo;`|left double quote
125 `‘`|`&lsquo;`|left single quote
126 `»`|`&raquo;`|right angle quote
127 `”`|`&rdquo;`|right double quote
128 `’`|`&rsquo;`|right single quote
129
130 ### Goldmark settings explained
131
132 Most of the Goldmark settings above are self-explanatory, but some require explanation.
133
134 `duplicateResourceFiles`
135 : (`bool`) Whether to duplicate shared page resources for each language on multilingual single-host projects. See [multilingual page resources][] for details. Default is `false`.
136
137 > [!NOTE]
138 > With multilingual single-host projects, setting this parameter to `false` will enable Hugo's [embedded link render hook][] and [embedded image render hook][]. This is the default configuration for multilingual single-host projects.
139
140 `parser.wrapStandAloneImageWithinParagraph`
141 : (`bool`) Whether to wrap image elements without adjacent content within a `p` element when rendered. This is the default Markdown behavior. Set to `false` when using an [image render hook][] to render standalone images as `figure` elements. Default is `true`.
142
143 `parser.autoDefinitionTermID`
144 : {{< new-in 0.144.0 />}}
145 : (`bool`) Whether to automatically add `id` attributes to description list terms (i.e., `dt` elements). When `true`, the `id` attribute of each `dt` element is accessible through the [`Fragments.Identifiers`][] method on a `Page` object.
146
147 `parser.autoHeadingID`
148 : (`bool`) Whether to automatically add `id` attributes to headings (i.e., `h1`, `h2`, `h3`, `h4`, `h5`, and `h6` elements).
149
150 `parser.autoIDType`
151 : (`string`) The strategy used to automatically generate `id` attributes, one of `github`, `github-ascii` or `blackfriday`. Default is `github`.
152
153 - `github`: Generate GitHub-compatible `id` attributes
154 - `github-ascii`: Drop any non-ASCII characters after accent normalization
155 - `blackfriday`: Generate `id` attributes compatible with the Blackfriday Markdown renderer
156
157 This is also the strategy used by the [`urls.Anchorize`][] function.
158
159 `parser.attribute.block`
160 : (`bool`) Whether to enable [Markdown attributes][] for block elements. Default is `false`.
161
162 `parser.attribute.title`
163 : (`bool`) Whether to enable [Markdown attributes][] for headings. Default is `true`.
164
165 `renderHooks.image.enableDefault`
166 : {{< deprecated-in 0.148.0 />}}
167 : Use the `renderHooks.image.useEmbedded` setting instead.
168
169 `renderHooks.image.useEmbedded`
170 : {{< new-in 0.148.0 />}}
171 : (`string`) When to use the [embedded image render hook][]. One of `auto`, `never`, `always`, or `fallback`. Default is `auto`.
172
173 - `auto`: Use the embedded image render hook only for multilingual single-host projects where the [duplication of shared page resources][] feature is disabled. If custom image render hooks are defined by your project, modules, or themes, these will be used instead.
174 - `never`: Never use the embedded image render hook. If custom image render hooks are defined by your project, modules, or themes, these will be used instead.
175 - `always`: Always use the embedded image render hook, even if custom image render hooks are provided by your project, modules, or themes.
176 - `fallback`: Use the embedded image render hook only if custom image render hooks are not provided by your project, modules, or themes. If custom image render hooks exist, these will be used instead.
177
178 `renderHooks.link.enableDefault`
179 : {{< deprecated-in 0.148.0 />}}
180 : Use the `renderHooks.link.useEmbedded` setting instead.
181
182 `renderHooks.link.useEmbedded`
183 : (`string`) When to use the [embedded link render hook][]. One of `auto`, `never`, `always`, or `fallback`. Default is `auto`.
184
185 - `auto`: Use the embedded link render hook only for multilingual single-host projects where the [duplication of shared page resources][] feature is disabled. If custom link render hooks are defined by your project, modules, or themes, these will be used instead.
186 - `never`: Never use the embedded link render hook. If custom link render hooks are defined by your project, modules, or themes, these will be used instead.
187 - `always`: Always use the embedded link render hook, even if custom link render hooks are provided by your project, modules, or themes.
188 - `fallback`: Use the embedded link render hook only if custom link render hooks are not provided by your project, modules, or themes. If custom link render hooks exist, these will be used instead.
189
190 `renderer.hardWraps`
191 : (`bool`) Whether to replace newline characters within a paragraph with `br` elements. Default is `false`.
192
193 `renderer.unsafe`
194 : (`bool`) Whether to render raw HTML mixed within Markdown. This is unsafe unless the content is under your control. Default is `false`.
195
196 ## AsciiDoc
197
198 This is the default configuration for the AsciiDoc renderer:
199
200 {{< code-toggle config=markup.asciidocExt />}}
201
202 ### AsciiDoc settings explained
203
204 `attributes`
205 : (`map`) A map of key-value pairs, each a document attribute. See Asciidoctor's [attributes][].
206
207 `backend`
208 : (`string`) The backend output file format. Default is `html5`.
209
210 `extensions`
211 : (`[]string`) An array of enabled extensions, such as `asciidoctor-html5s`, `asciidoctor-bibtex`, or `asciidoctor-diagram`.
212
213 > [!NOTE]
214 > To mitigate security risks, entries in the extension array may not contain forward slashes (`/`), backslashes (`\`), or periods. Due to this restriction, extensions must be in Ruby's `$LOAD_PATH`.
215
216 `failureLevel`
217 : (`string`) The minimum logging level that triggers a non-zero exit code (failure). Default is `fatal`.
218
219 `noHeaderOrFooter`
220 : (`bool`) Whether to output an embeddable document, which excludes the header, the footer, and everything outside the body of the document. Default is `true`.
221
222 `preserveTOC`
223 : (`bool`) Whether to preserve the table of contents (TOC) rendered by Asciidoctor. By default, to make the TOC compatible with existing themes, Hugo removes the TOC rendered by Asciidoctor. To render the TOC, use the [`TableOfContents`][] method on a `Page` object in your templates. Default is `false`.
224
225 `safeMode`
226 : (`string`) The safe mode level, one of `unsafe`, `safe`, `server`, or `secure`. Default is `unsafe`.
227
228 `sectionNumbers`
229 : (`bool`) Whether to number each section title. Default is `false`.
230
231 `trace`
232 : (`bool`) Whether to include backtrace information on errors. Default is `false`.
233
234 `verbose`
235 : (`bool`) Whether to verbosely print processing information and configuration file checks to stderr. Default is `false`.
236
237 `workingFolderCurrent`
238 : (`bool`) Whether to set the working directory to be the same as that of the AsciiDoc file being processed, allowing [includes][] to work with relative paths. Set to `true` to render diagrams with the [asciidoctor-diagram][] extension. Default is `false`.
239
240 ### Configuration example
241
242 {{< code-toggle file=hugo >}}
243 [markup.asciidocExt]
244 extensions = ['asciidoctor-html5s','asciidoctor-diagram']
245 workingFolderCurrent = true
246 [markup.asciidocExt.attributes]
247 my-base-url = 'https://example.com/'
248 my-attribute-name = 'my value'
249 {{< /code-toggle >}}
250
251 ### Syntax highlighting
252
253 Follow the steps below to enable syntax highlighting.
254
255 Step 1
256 : Set the `source-highlighter` attribute in your project configuration. For example:
257
258 {{< code-toggle file=hugo >}}
259 [markup.asciidocExt.attributes]
260 source-highlighter = 'rouge'
261 {{< /code-toggle >}}
262
263 Step 2
264 : Generate the highlighter CSS. For example:
265
266 ```sh
267 rougify style monokai.sublime > assets/css/syntax.css
268 ```
269
270 Step 3
271 : In your base template add a link to the CSS file:
272
273 ```go-html-template {file="layouts/baseof.html"}
274 <head>
275 ...
276 {{ with resources.Get "css/syntax.css" }}
277 <link rel="stylesheet" href="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous">
278 {{ end }}
279 ...
280 </head>
281 ```
282
283 Step 4
284 : Add the code to be highlighted to your markup:
285
286 ```text
287 [#hello,ruby]
288 ----
289 require 'sinatra'
290
291 get '/hi' do
292 "Hello World!"
293 end
294 ----
295 ```
296
297 ### Troubleshooting
298
299 Run `hugo build --logLevel debug` to examine Hugo's call to the Asciidoctor executable:
300
301 ```txt
302 INFO 2019/12/22 09:08:48 Rendering book-as-pdf.adoc with C:\Ruby26-x64\bin\asciidoctor.bat using asciidoc args [--no-header-footer -r asciidoctor-html5s -b html5s -r asciidoctor-diagram --base-dir D:\prototypes\hugo_asciidoc_ddd\docs -a outdir=D:\prototypes\hugo_asciidoc_ddd\build -] ...
303 ```
304
305 ## Highlight
306
307 This is the default configuration.
308
309 {{< code-toggle config=markup.highlight />}}
310
311 {{% include "/_common/syntax-highlighting-options.md" %}}
312
313 ## Table of contents
314
315 This is the default configuration for the table of contents, applicable to Goldmark and Asciidoctor:
316
317 {{< code-toggle config=markup.tableOfContents />}}
318
319 `startLevel`
320 : (`int`) Heading levels less than this value will be excluded from the table of contents. For example, to exclude `h1` elements from the table of contents, set this value to `2`. Default is `2`.
321
322 `endLevel`
323 : (`int`) Heading levels greater than this value will be excluded from the table of contents. For example, to exclude `h4`, `h5`, and `h6` elements from the table of contents, set this value to `3`. Default is `3`.
324
325 `ordered`
326 : (`bool`) Whether to generates an ordered list instead of an unordered list. Default is `false`.
327
328 [^1]: See [details](https://github.com/gohugoio/hugo-goldmark-extensions/commit/4d4fcd022fe45a9b51483df001c9e5f4e632d5a9).
329
330 [AsciiDoc]: https://asciidoc.org/
331 [CommonMark]: https://spec.commonmark.org/current/
332 [Emacs Org Mode]: https://orgmode.org/
333 [GitHub Flavored Markdown: Autolinks]: https://github.github.com/gfm/#autolinks-extension-
334 [GitHub Flavored Markdown: Strikethrough]: https://github.github.com/gfm/#strikethrough-extension-
335 [GitHub Flavored Markdown: Tables]: https://github.github.com/gfm/#tables-extension-
336 [GitHub Flavored Markdown: Task list items]: https://github.github.com/gfm/#task-list-items-extension-
337 [GitHub Flavored Markdown]: https://github.github.com/gfm/
338 [Goldmark Extensions: CJK]: https://github.com/yuin/goldmark?tab=readme-ov-file#cjk-extension
339 [Goldmark Extensions: Typographer]: https://github.com/yuin/goldmark?tab=readme-ov-file#typographer-extension
340 [Goldmark]: https://github.com/yuin/goldmark/
341 [Hugo Goldmark Extensions: Extras]: https://github.com/gohugoio/hugo-goldmark-extensions?tab=readme-ov-file#extras-extension
342 [Hugo Goldmark Extensions: Passthrough]: https://github.com/gohugoio/hugo-goldmark-extensions?tab=readme-ov-file#passthrough-extension
343 [Markdown attributes]: /content-management/markdown-attributes/
344 [PHP Markdown Extra: Definition lists]: https://michelf.ca/projects/php-markdown/extra/#def-list
345 [PHP Markdown Extra: Footnotes]: https://michelf.ca/projects/php-markdown/extra/#footnotes
346 [Pandoc]: https://pandoc.org/
347 [`Fragments.Identifiers`]: /methods/page/fragments/#identifiers
348 [`TableOfContents`]: /methods/page/tableofcontents/
349 [`urls.Anchorize`]: /functions/urls/anchorize/
350 [asciidoctor-diagram]: https://asciidoctor.org/docs/asciidoctor-diagram/
351 [attributes]: https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#attributes-and-substitutions
352 [deleted text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del
353 [duplication of shared page resources]: /configuration/markup/#duplicateresourcefiles
354 [embedded image render hook]: /render-hooks/images/#embedded
355 [embedded link render hook]: /render-hooks/links/#embedded
356 [image render hook]: /render-hooks/images/
357 [includes]: https://docs.asciidoctor.org/asciidoc/latest/syntax-quick-reference/#includes
358 [inserted text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins
359 [mark text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark
360 [mathematics in Markdown]: /content-management/mathematics/
361 [multilingual page resources]: /content-management/page-resources/#multilingual
362 [reStructuredText]: https://docutils.sourceforge.io/rst.html
363 [security policy]: /configuration/security/
364 [subscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub
365 [superscript]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup