hugo/content/en/getting-started/configuration-markup.md
Bjørn Erik Pedersen c9403cbcea Squashed 'docs/' changes from ec0abe052..6c2195936
6c2195936 Update featured.png
109a0fcca add len function to navigation side menu
39a356bc5 Revert "Add some rickrolls redirects"
b8393b1b5 Add some rickrolls redirects
2ce21c34b Update configuration-markup.md (add rel="noopener")
95bd7974e Disambiguate global and page resources
5e233dc4b Update base.md
959b9dc3a Fix typo on "where" page
aff8059a1 Release 0.70.0
44a172ac0 releaser: Add release notes to /docs for release of 0.70.0
1b01c8988 Release 0.70.0
5ece21c6c Merge commit '89044b8f8795f17c36396c67823183a20fc88139'
0894aec5b Rename transpileJS to babel
5da27c7a6 resources: Add JavaScript transpiling solution

git-subtree-dir: docs
git-subtree-split: 6c21959360394165435fa36eac489bf6a701ae9a
2020-05-18 15:24:58 +02:00

5.5 KiB

title description date categories keywords weight sections_weight slug toc
Configure Markup How to handle Markdown and other markup related configuration. 2019-11-15
getting started
fundamentals
configuration
highlighting
65 65 configuration-markup true

Configure Markup

{{< new-in "0.60.0" >}}

See Goldmark for settings related to the default Markdown handler in Hugo.

Below are all markup related configuration in Hugo with their default settings:

{{< code-toggle config="markup" />}}

See each section below for details.

Goldmark

Goldmark is from Hugo 0.60 the default library used for Markdown. It's fast, it's CommonMark compliant and it's very flexible. Note that the feature set of Goldmark vs Blackfriday isn't the same; you gain a lot but also lose some, but we will work to bridge any gap in the upcoming Hugo versions.

This is the default configuration:

{{< code-toggle config="markup.goldmark" />}}

Some settings explained:

unsafe
By default, Goldmark does not render raw HTMLs and potentially dangerous links. If you have lots of inline HTML and/or JavaScript, you may need to turn this on.
typographer
This extension substitutes punctuations with typographic entities like smartypants.
autoHeadingIDType ("github") {{< new-in "0.62.2" >}}
The strategy used for creating auto IDs (anchor names). Available types are github, github-ascii and blackfriday. github produces GitHub-compatible IDs, github-ascii will drop any non-Ascii characters after accent normalization, and blackfriday will make the IDs work as with Blackfriday, the default Markdown engine before Hugo 0.60. Note that if Goldmark is your default Markdown engine, this is also the strategy used in the anchorize template func.

Blackfriday

Blackfriday was Hugo's default Markdown rendering engine, now replaced with Goldmark. But you can still use it: Just set defaultMarkdownHandler to blackfriday in your top level markup config.

This is the default config:

{{< code-toggle config="markup.blackFriday" />}}

Highlight

This is the default highlight configuration. Note that some of these settings can be set per code block, see Syntax Highlighting.

{{< code-toggle config="markup.highlight" />}}

For style, see these galleries:

For CSS, see Generate Syntax Highlighter CSS.

Table Of Contents

{{< code-toggle config="markup.tableOfContents" />}}

These settings only works for the Goldmark renderer:

startLevel
The heading level, values starting at 1 (h1), to start render the table of contents.
endLevel
The heading level, inclusive, to stop render the table of contents.
ordered
Whether or not to generate an ordered list instead of an unordered list.

Markdown Render Hooks

{{< new-in "0.62.0" >}}

Note that this is only supported with the Goldmark renderer.

These Render Hooks allow custom templates to render links and images from markdown.

You can do this by creating templates with base names render-link and/or render-image inside layouts/_default/_markup.

You can define Output-Format- and language-specific templates if needed.1 Your layouts folder may look like this:

layouts
└── _default
    └── _markup
        ├── render-image.html
        ├── render-image.rss.xml
        └── render-link.html

Some use cases for the above:

  • Resolve link references using .GetPage. This would make links portable as you could translate ./my-post.md (and similar constructs that would work on GitHub) into /blog/2019/01/01/my-post/ etc.
  • Add target=_blank to external links.
  • Resolve and process images.

Render Hook Templates

Both render-link and render-image templates will receive this context:

Page
The Page being rendered.
Destination
The URL.
Title
The title attribute.
Text
The rendered (HTML) link text.
PlainText
The plain variant of the above.
[Text](https://www.gohugo.io "Title")

Here is a code example for how the render-link.html template could look:

{{< code file="layouts/_default/_markup/render-link.html" >}} <a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }} {{< /code >}}

Image Markdown example:

![Text](https://d33wubrfki0l68.cloudfront.net/c38c7334cc3f23585738e40334284fddcaf03d5e/2e17c/images/hugo-logo-wide.svg "Title")

Here is a code example for how the render-image.html template could look:

{{< code file="layouts/_default/_markup/render-image.html" >}}

{{ .Text }}

{{< /code >}}

  1. It's currently only possible to have one set of render hook templates, e.g. not per Type or Section. We may consider that in a future version. ↩︎