Rework content formats

This commit is contained in:
Joe Mooring
2024-05-03 14:48:23 -07:00
committed by GitHub
parent 886f952e00
commit 9b0c02e460
7 changed files with 115 additions and 76 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ toc: true
## Content authoring ## Content authoring
[Content formats] [Content formats]
: Create your content using Markdown, HTML, AsciiDoc, Pandoc, reStructuredText, or Emacs Org Mode. Markdown is the default content format, conforming to the [CommonMark] and [GitHub Flavored Markdown] specifications. : Create your content using Markdown, HTML, AsciiDoc, Emacs Org Mode, Pandoc, or reStructuredText. Markdown is the default content format, conforming to the [CommonMark] and [GitHub Flavored Markdown] specifications.
[Markdown attributes] [Markdown attributes]
: Apply HTML attributes such as `class` and `id` to Markdown images and block elements including blockquotes, fenced code blocks, headings, horizontal rules, lists, paragraphs, and tables. : Apply HTML attributes such as `class` and `id` to Markdown images and block elements including blockquotes, fenced code blocks, headings, horizontal rules, lists, paragraphs, and tables.
+1 -1
View File
@@ -24,7 +24,7 @@ But when developing and building your site, the runtime is the `hugo` executable
* Hugo has a virtual file system and only the main project (not third-party components) is allowed to mount directories or files outside the project root. * Hugo has a virtual file system and only the main project (not third-party components) is allowed to mount directories or files outside the project root.
* Only the main project can walk symbolic links. * Only the main project can walk symbolic links.
* User-defined components have read-only access to the filesystem. * User-defined components have read-only access to the filesystem.
* We shell out to some external binaries to support [Asciidoctor](/content-management/formats/#list-of-content-formats) and similar, but those binaries and their flags are predefined and disabled by default (see [Security Policy](#security-policy)). General functions to run arbitrary external OS commands have been [discussed](https://github.com/gohugoio/hugo/issues/796), but not implemented because of security concerns. * We shell out to some external binaries to support [Asciidoctor](/content-management/formats/#formats) and similar, but those binaries and their flags are predefined and disabled by default (see [Security Policy](#security-policy)). General functions to run arbitrary external OS commands have been [discussed](https://github.com/gohugoio/hugo/issues/796), but not implemented because of security concerns.
## Security policy ## Security policy
+105 -61
View File
@@ -1,6 +1,6 @@
--- ---
title: Content formats title: Content formats
description: Both HTML and Markdown are supported content formats. description: Create your content using Markdown, HTML, Emacs Org Mode, AsciiDoc, Pandoc, or reStructuredText.
categories: [content management] categories: [content management]
keywords: [markdown,asciidoc,pandoc,content format] keywords: [markdown,asciidoc,pandoc,content format]
menu: menu:
@@ -12,82 +12,126 @@ toc: true
aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/] aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/]
--- ---
You can put any file type into your `/content` directories, but Hugo uses the `markup` front matter value if set or the file extension (see `Markup identifiers` in the table below) to determine if the markup needs to be processed, e.g.: ## Introduction
* Markdown converted to HTML You may mix content formats throughout your site. For example:
* [Shortcodes](/content-management/shortcodes/) processed
* Layout applied
## List of content formats ```text
content/
└── posts/
├── post-1.md
├── post-2.adoc
├── post-3.org
├── post-4.pandoc
├── post-5.rst
└── post-6.html
```
The current list of content formats in Hugo: Regardless of content format, all content must have [front matter], preferably including both `title` and `date`.
| Name | Markup identifiers | Comment | Hugo selects the content renderer based on the `markup` identifier in front matter, falling back to the file extension. See the [comparison table](#comparison) table below for a list of markup identifiers and recognized file extensions.
| ------------- | ------------- |-------------|
| Goldmark | `markdown`, `goldmark` |Note that you can set the default handler of `md` and `markdown` to something else, see [Configure Markup](/getting-started/configuration-markup/).|
|Emacs Org-Mode|`org`|See [go-org](https://github.com/niklasfasching/go-org).|
|AsciiDoc|`asciidocext`, `adoc`, `ad`|Needs [Asciidoctor][ascii] installed.|
|RST|`rst`|Needs [RST](https://docutils.sourceforge.io/rst.html) installed.|
|Pandoc|`pandoc`, `pdc`|Needs [Pandoc](https://www.pandoc.org/) installed.|
|HTML|`html`, `htm`|To be treated as a content file, with layout, shortcodes etc., it must have front matter.|
The `markup` identifier is fetched from either the `markup` field in front matter or from the file extension. For markup-related configuration, see [Configure Markup](/getting-started/configuration-markup/). ## Formats
## External helpers ### Markdown
Some of the formats in the table above need external helpers installed on your PC. For example, for AsciiDoc files, Create your content in [Markdown] preceded by front matter.
Hugo will try to call the `asciidoctor` command. This means that you will have to install the associated
tool on your machine to be able to use these formats.
Hugo passes reasonable default arguments to these external helpers by default: Markdown is Hugo's default content format. Hugo natively renders Markdown to HTML using [Goldmark]. Goldmark is fast and conforms to the [CommonMark] and [GitHub Flavored Markdown] specifications. You can [configure Goldmark] in your site configuration.
- `asciidoctor`: `--no-header-footer -` Hugo provides custom Markdown features including:
- `rst2html`: `--leave-comments --initial-header-level=2`
- `pandoc`: `--mathjax`
{{% note %}} [Attributes]
Because additional formats are external commands, generation performance will rely heavily on the performance of the external tool you are using. As this feature is still in its infancy, feedback is welcome. : Apply HTML attributes such as `class` and `id` to Markdown images and block elements including blockquotes, fenced code blocks, headings, horizontal rules, lists, paragraphs, and tables.
{{% /note %}}
### Asciidoctor [Extensions]
: Leverage the embedded Markdown extensions to create tables, definition lists, footnotes, task lists, and more.
The Asciidoctor community offers a wide set of tools for the AsciiDoc format that can be installed additionally to Hugo. [Mathematics]
[See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/). Make sure that also all : Include mathematical equations and expressions in Markdown using LaTeX or TeX typesetting syntax.
optional extensions like `asciidoctor-diagram` or `asciidoctor-html5s` are installed if required.
{{% note %}} [Render hooks]
External `asciidoctor` command requires Hugo rendering to _disk_ to a specific destination directory. It is required to run Hugo with the command option `--destination`. : Override the conversion of Markdown to HTML when rendering fenced code blocks, headings, images, and links. For example, render every standalone image as an HTML `figure` element.
{{% /note %}}
Some Asciidoctor parameters can be customized in Hugo. See [details]. ### HTML
[details]: /getting-started/configuration-markup/#asciidoc Create your content in [HTML] preceded by front matter. The content is typically what you would place within an HTML document's `body` or `main` element.
## Learn Markdown ### Emacs Org Mode
Markdown syntax is simple enough to learn in a single sitting. The following are excellent resources to get you up and running: Create your content in the [Emacs Org Mode] format preceded by front matter. You can use Org Mode keywords for front matter. See [details](http://localhost:1313/content-management/front-matter/#emacs-org-mode).
* [Daring Fireball: Markdown, John Gruber (Creator of Markdown)][fireball] ### AsciiDoc
* [Markdown Cheatsheet, Adam Pritchard][mdcheatsheet]
* [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial]
* [The Markdown Guide, Matt Cone][mdguide]
[ascii]: https://asciidoctor.org/ Create your content in the [AsciiDoc] format preceded by front matter. Hugo renders AsciiDoc content to HTML using the Asciidoctor executable. You must install Asciidoctor and its dependencies (Ruby) to use the AsciiDoc content format.
[config]: /getting-started/configuration/
[developer tools]: /tools/ You can [configure the AsciiDoc renderer] in your site configuration.
[fireball]: https://daringfireball.net/projects/Markdown/
[gfmtasks]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#syntax In its default configuration, Hugo passes these CLI flags when calling the Asciidoctor executable:
[helperssource]: https://github.com/gohugoio/hugo/blob/77c60a3440806067109347d04eb5368b65ea0fe8/helpers/general.go#L65
[hl]: /content-management/syntax-highlighting/ ```text
[hlsc]: /content-management/shortcodes/#highlight --no-header-footer
[hugocss]: /css/style.css ```
[ietf]: https://tools.ietf.org/html/
[mathjaxdocs]: https://docs.mathjax.org/en/latest/ The CLI flags passed to the Asciidoctor executable depend on configuration. You may inspect the flags when building your site:
[mdcheatsheet]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
[mdguide]: https://www.markdownguide.org/ ```text
[mdtutorial]: https://www.markdowntutorial.com/ hugo --logLevel info
[org]: https://orgmode.org/ ```
[pandoc]: https://www.pandoc.org/
[rest]: https://docutils.sourceforge.io/rst.html ### Pandoc
[sc]: /content-management/shortcodes/
[sct]: /templates/shortcode-templates/ Create your content in the [Pandoc] format preceded by front matter. Hugo renders Pandoc content to HTML using the Pandoc executable. You must install Pandoc to use the Pandoc content format.
Hugo passes these CLI flags when calling the Pandoc executable:
```text
--mathjax
```
### reStructuredText
Create your content in the [reStructuredText] format preceded by front matter. Hugo renders reStructuredText content to HTML using [Docutils], specifically rst2html. You must install Docutils and its dependencies (Python) to use the reStructuredText content format.
Hugo passes these CLI flags when calling the rst2html executable:
```text
--leave-comments --initial-header-level=2
```
## Comparison
Content format|Identifier|Identifier aliases|File extensions
:--|:--|:--|:--
Markdown|`goldmark`|`md`, `mdown`, `markdown`|`md`, `mdown`, `markdown`
HTML|`html`|`htm`|`html`, `htm`
Emacs Org Mode|`org`||`org`
AsciiDoc|`asciidocext`|`adoc`, `ad`|`adoc`, `ad`
Pandoc|`pandoc`|`pdc`|`pandoc`, `pdc`
reStructuredText|`rst`||`rst`
When converting content to HTML, Hugo uses:
- Native renderers for Markdown, HTML, and Emacs Org mode
- External renderers for AsciiDoc, Pandoc, and reStructuredText
Native renderers are faster than external renderers.
[AsciiDoc]: https://asciidoc.org/
[Asciidoctor]: https://asciidoctor.org/
[Attributes]: /content-management/markdown-attributes/
[CommonMark]: https://spec.commonmark.org/current/
[Docutils]: https://docutils.sourceforge.io/
[Emacs Org Mode]: https://orgmode.org/
[Extensions]: /getting-started/configuration-markup/#goldmark-extensions
[GitHub Flavored Markdown]: https://github.github.com/gfm/
[Goldmark]: https://github.com/yuin/goldmark
[HTML]: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics
[Markdown]: https://daringfireball.net/projects/markdown/
[Mathematics]: /content-management/mathematics/
[Pandoc]: https://pandoc.org/
[Render hooks]: https://gohugo.io/render-hooks/introduction/
[configure Goldmark]: /getting-started/configuration-markup/#goldmark
[configure the AsciiDoc renderer]: /getting-started/configuration-markup/#asciidoc
[front matter]: /content-management/front-matter/
[reStructuredText]: https://docutils.sourceforge.io/rst.html
+2 -11
View File
@@ -161,18 +161,9 @@ lang
###### markup ###### markup
(`string`) A identifier corresponding to one of the supported [content formats]: (`string`) An identifier corresponding to one of the supported [content formats]. If not provided, Hugo determines the content renderer based on the file extension.
Identifier|Content format [content formats]: /content-management/formats/#comparison
:--|:--
`adoc`|Asciidoc
`html`|HTML
`md`|Markdown
`org`|Emacs Org Mode
`pdc`|Pandoc
`rst`|reStructuredText
[content formats]: /content-management/formats/
###### menus ###### menus
@@ -43,7 +43,7 @@ Unless you need a unique capability provided by one of the alternate Markdown ha
{{% /note %}} {{% /note %}}
[asciidoc]: https://asciidoc.org/ [asciidoc]: https://asciidoc.org/
[content format]: /content-management/formats/#list-of-content-formats [content format]: /content-management/formats/#formats
[emacs org mode]: https://orgmode.org/ [emacs org mode]: https://orgmode.org/
[goldmark]: https://github.com/yuin/goldmark/ [goldmark]: https://github.com/yuin/goldmark/
[pandoc]: https://pandoc.org/ [pandoc]: https://pandoc.org/
+4
View File
@@ -82,6 +82,10 @@ Within a template, to connect one or more [identifiers](#identifier) with a dot.
A collective term for the Chinese, Japanese, and Korean languages. See [details](https://en.wikipedia.org/wiki/CJK_characters). A collective term for the Chinese, Japanese, and Korean languages. See [details](https://en.wikipedia.org/wiki/CJK_characters).
###### CLI
Command line interface.
###### collection ###### collection
An [array](#array), [slice](#slice), or [map](#map). An [array](#array), [slice](#slice), or [map](#map).
+1 -1
View File
@@ -47,5 +47,5 @@ Render with [Pandoc]:
{{ .RenderString $opts $s }} → <p>H<sub>2</sub>O</p> {{ .RenderString $opts $s }} → <p>H<sub>2</sub>O</p>
``` ```
[markup identifier]: /content-management/formats/#list-of-content-formats [markup identifier]: /content-management/formats/#formats
[pandoc]: https://www.pandoc.org/ [pandoc]: https://www.pandoc.org/