mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
14e369b961
988f7d5c2 Document default `enableInlineShortcodes` value 0f604a345 Fix typo in 0.66.0 release note 26fc74fe3 How to access individual EXIF data tags d5d3bad9a Fix localhost links fa6921213 Update index.md 5bf558f78 Release 0.66.0 74ccdaaf5 Merge branch 'temp660' 75faa478b releaser: Add release notes to /docs for release of 0.66.0 c4a4a9922 docs: Regen CLI docs 0624ac198 Add build.UseResourceCacheWhen 58a8d7cd1 Add build options documentation d926c595e fix typo 99713d44b resources: Add basic @import support to resources.PostCSS 224b96cf7 deploy: Implement include/exclude filters for deploy eb1a00050 Adjusting description; WordPress with capitalized P 91d8efa22 Add another tool for migration from the Wordpress a6938a4ac Adjust showcase description a9c0a0a69 Adjust showcase e5af08aa6 Adding Aether as a proposed showcase item. 0013daa34 Add hugo.IsProduction function 34c419ef3 tpl: Add math.Sqrt 5bdab0ebd Update minification.md 9039332e2 Hugo 0.65.3 1400caf3a Merge branch 'temp653' 9796bb337 releaser: Add release notes to /docs for release of 0.65.3 65b26598f Fix typo 23aa57d80 Fix crashes for 404 in IsAncestor etc. 42c54bc6c 0.65.2 67fd5c1f6 Merge branch 'temp652' d820ac017 releaser: Add release notes to /docs for release of 0.65.2 51f0888ff Release 0.65.1 91e95260c releaser: Add release notes to /docs for release of 0.65.1 1880ebf05 fix broken link on internal.md ffaa33889 Update migrations.md de4d64675 Another tool for migration from Medium platform 90b178d77 releaser: Add release notes to /docs for release of 0.65.1 6925cda30 Handle corner case with rendering text as code in URL 3cb4b19dd Release 0.65.0 7a600cb99 Merge branch 'temp650' ef9531ff6 releaser: Add release notes to /docs for release of 0.65.0 9bc19606f docs: Regenerate CLI docs d4a886ed2 Add Page.GetTerms a3bf273a5 fix broken link on use-modules.md 001f52f4e Fix mage URL in development.md eef72e887 Merge commit '4b670bc8cc38103c2c60e5090c2f56bf30832b8d' b18a76631 commands: Support "hugo mod get -u ./..." git-subtree-dir: docs git-subtree-split: 988f7d5c2d7a1d40ec2c8ab961cb5a4e41b5bd4c
155 lines
5.5 KiB
Markdown
155 lines
5.5 KiB
Markdown
---
|
|
title: Configure Markup
|
|
description: How to handle Markdown and other markup related configuration.
|
|
date: 2019-11-15
|
|
categories: [getting started,fundamentals]
|
|
keywords: [configuration,highlighting]
|
|
weight: 65
|
|
sections_weight: 65
|
|
slug: configuration-markup
|
|
toc: true
|
|
---
|
|
|
|
## Configure Markup
|
|
|
|
{{< new-in "0.60.0" >}}
|
|
|
|
See [Goldmark](#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](https://github.com/yuin/goldmark/) is from Hugo 0.60 the default library used for Markdown. It's fast, it's [CommonMark](https://spec.commonmark.org/0.29/) 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](https://daringfireball.net/projects/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](#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](/functions/anchorize/) template func.
|
|
|
|
### Blackfriday
|
|
|
|
|
|
[Blackfriday](https://github.com/russross/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](/content-management/syntax-highlighting/).
|
|
|
|
{{< code-toggle config="markup.highlight" />}}
|
|
|
|
For `style`, see these galleries:
|
|
|
|
* [Short snippets](https://xyproto.github.io/splash/docs/all.html)
|
|
* [Long snippets](https://xyproto.github.io/splash/docs/longer/all.html)
|
|
|
|
For CSS, see [Generate Syntax Highlighter CSS](/content-management/syntax-highlighting/#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](#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-](/templates/output-formats) and [language-](/content-management/multilingual/)specific templates if needed.[^hooktemplate] Your `layouts` folder may look like this:
|
|
|
|
```bash
|
|
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](/content-management/image-processing/) images.
|
|
|
|
### Render Hook Templates
|
|
|
|
Both `render-link` and `render-image` templates will receive this context:
|
|
|
|
Page
|
|
: The [Page](/variables/page/) being rendered.
|
|
|
|
Destination
|
|
: The URL.
|
|
|
|
Title
|
|
: The title attribute.
|
|
|
|
Text
|
|
: The rendered (HTML) link text.
|
|
|
|
PlainText
|
|
: The plain variant of the above.
|
|
|
|
#### Link with title Markdown example :
|
|
|
|
```md
|
|
[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"{{ end }}>{{ .Text | safeHTML }}</a>
|
|
{{< /code >}}
|
|
|
|
#### Image Markdown example:
|
|
|
|
```md
|
|
![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" >}}
|
|
<p class="md__image">
|
|
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} />
|
|
</p>
|
|
{{< /code >}}
|
|
|
|
[^hooktemplate]: 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.
|
|
|