From 9b0c02e4605dcf2601aa9ed0614f91ca470d2784 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Fri, 3 May 2024 14:48:23 -0700 Subject: [PATCH] Rework content formats --- content/en/about/features.md | 2 +- content/en/about/security.md | 2 +- content/en/content-management/formats.md | 166 +++++++++++------- content/en/content-management/front-matter.md | 13 +- .../getting-started/configuration-markup.md | 2 +- content/en/getting-started/glossary.md | 4 + content/en/methods/page/RenderString.md | 2 +- 7 files changed, 115 insertions(+), 76 deletions(-) diff --git a/content/en/about/features.md b/content/en/about/features.md index 24ae0d8f7..44b00996f 100644 --- a/content/en/about/features.md +++ b/content/en/about/features.md @@ -40,7 +40,7 @@ toc: true ## Content authoring [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] : 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. diff --git a/content/en/about/security.md b/content/en/about/security.md index f48572f12..008cd6814 100644 --- a/content/en/about/security.md +++ b/content/en/about/security.md @@ -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. * Only the main project can walk symbolic links. * 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 diff --git a/content/en/content-management/formats.md b/content/en/content-management/formats.md index 7434733c2..305679b21 100644 --- a/content/en/content-management/formats.md +++ b/content/en/content-management/formats.md @@ -1,6 +1,6 @@ --- 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] keywords: [markdown,asciidoc,pandoc,content format] menu: @@ -12,82 +12,126 @@ toc: true 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 -* [Shortcodes](/content-management/shortcodes/) processed -* Layout applied +You may mix content formats throughout your site. For example: -## 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 | -| ------------- | ------------- |-------------| -| 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.| +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. -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, -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. +Create your content in [Markdown] preceded by front matter. -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 -` -- `rst2html`: `--leave-comments --initial-header-level=2` -- `pandoc`: `--mathjax` +Hugo provides custom Markdown features including: -{{% note %}} -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. -{{% /note %}} +[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. -### 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. -[See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/). Make sure that also all -optional extensions like `asciidoctor-diagram` or `asciidoctor-html5s` are installed if required. +[Mathematics] +: Include mathematical equations and expressions in Markdown using LaTeX or TeX typesetting syntax. -{{% note %}} -External `asciidoctor` command requires Hugo rendering to _disk_ to a specific destination directory. It is required to run Hugo with the command option `--destination`. -{{% /note %}} +[Render hooks] +: 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. -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] -* [Markdown Cheatsheet, Adam Pritchard][mdcheatsheet] -* [Markdown Tutorial (Interactive), Garen Torikian][mdtutorial] -* [The Markdown Guide, Matt Cone][mdguide] +### AsciiDoc -[ascii]: https://asciidoctor.org/ -[config]: /getting-started/configuration/ -[developer tools]: /tools/ -[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 -[helperssource]: https://github.com/gohugoio/hugo/blob/77c60a3440806067109347d04eb5368b65ea0fe8/helpers/general.go#L65 -[hl]: /content-management/syntax-highlighting/ -[hlsc]: /content-management/shortcodes/#highlight -[hugocss]: /css/style.css -[ietf]: https://tools.ietf.org/html/ -[mathjaxdocs]: https://docs.mathjax.org/en/latest/ -[mdcheatsheet]: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet -[mdguide]: https://www.markdownguide.org/ -[mdtutorial]: https://www.markdowntutorial.com/ -[org]: https://orgmode.org/ -[pandoc]: https://www.pandoc.org/ -[rest]: https://docutils.sourceforge.io/rst.html -[sc]: /content-management/shortcodes/ -[sct]: /templates/shortcode-templates/ +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. + +You can [configure the AsciiDoc renderer] in your site configuration. + +In its default configuration, Hugo passes these CLI flags when calling the Asciidoctor executable: + +```text +--no-header-footer +``` + +The CLI flags passed to the Asciidoctor executable depend on configuration. You may inspect the flags when building your site: + +```text +hugo --logLevel info +``` + +### Pandoc + +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 diff --git a/content/en/content-management/front-matter.md b/content/en/content-management/front-matter.md index fd54370cc..8ea41487d 100644 --- a/content/en/content-management/front-matter.md +++ b/content/en/content-management/front-matter.md @@ -161,18 +161,9 @@ lang ###### 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 -:--|:-- -`adoc`|Asciidoc -`html`|HTML -`md`|Markdown -`org`|Emacs Org Mode -`pdc`|Pandoc -`rst`|reStructuredText - -[content formats]: /content-management/formats/ +[content formats]: /content-management/formats/#comparison ###### menus diff --git a/content/en/getting-started/configuration-markup.md b/content/en/getting-started/configuration-markup.md index ecf5c7194..7c3185f62 100644 --- a/content/en/getting-started/configuration-markup.md +++ b/content/en/getting-started/configuration-markup.md @@ -43,7 +43,7 @@ Unless you need a unique capability provided by one of the alternate Markdown ha {{% /note %}} [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/ [goldmark]: https://github.com/yuin/goldmark/ [pandoc]: https://pandoc.org/ diff --git a/content/en/getting-started/glossary.md b/content/en/getting-started/glossary.md index c9a965f7c..020738000 100644 --- a/content/en/getting-started/glossary.md +++ b/content/en/getting-started/glossary.md @@ -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). +###### CLI + +Command line interface. + ###### collection An [array](#array), [slice](#slice), or [map](#map). diff --git a/content/en/methods/page/RenderString.md b/content/en/methods/page/RenderString.md index 5782cd2b1..0f2df111f 100644 --- a/content/en/methods/page/RenderString.md +++ b/content/en/methods/page/RenderString.md @@ -47,5 +47,5 @@ Render with [Pandoc]: {{ .RenderString $opts $s }} →

H2O

``` -[markup identifier]: /content-management/formats/#list-of-content-formats +[markup identifier]: /content-management/formats/#formats [pandoc]: https://www.pandoc.org/