summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-06 20:10:47 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-11-23 14:12:24 +0100
commitbfb9613a14ab2d93a4474e5486d22e52a9d5e2b3 (patch)
tree81c4dbd10505e952489e1dbcf1d7bafc88b57c28
parenta3fe5e5e35f311f22b6b4fc38abfcf64cd2c7d6f (diff)
Add Goldmark as the new default markdown handler
This commit adds the fast and CommonMark compliant Goldmark as the new default markdown handler in Hugo. If you want to continue using BlackFriday as the default for md/markdown extensions, you can use this configuration: ```toml [markup] defaultMarkdownHandler="blackfriday" ``` Fixes #5963 Fixes #1778 Fixes #6355
-rw-r--r--commands/genchromastyles.go2
-rw-r--r--docs/config.toml12
-rw-r--r--docs/config/_default/config.toml16
-rw-r--r--docs/content/en/about/features.md2
-rw-r--r--docs/content/en/content-management/formats.md198
-rw-r--r--docs/content/en/content-management/syntax-highlighting.md181
-rw-r--r--docs/content/en/contribute/documentation.md1
-rw-r--r--docs/content/en/functions/highlight.md6
-rw-r--r--docs/content/en/getting-started/configuration-markup.md73
-rw-r--r--docs/content/en/getting-started/configuration.md48
-rw-r--r--docs/content/en/getting-started/installing.md6
-rw-r--r--docs/content/en/readfiles/bfconfig.md197
-rw-r--r--docs/content/en/templates/shortcode-templates.md4
-rw-r--r--docs/data/docs.json167
-rw-r--r--docs/layouts/shortcodes/code-toggle.html34
-rw-r--r--docs/layouts/shortcodes/new-in.html8
-rw-r--r--docs/requirements.txt1
-rw-r--r--go.mod3
-rw-r--r--go.sum8
-rw-r--r--helpers/content.go45
-rw-r--r--helpers/general.go27
-rw-r--r--helpers/general_test.go13
-rw-r--r--helpers/pygments.go402
-rw-r--r--helpers/pygments_test.go300
-rw-r--r--hugolib/case_insensitive_test.go1
-rw-r--r--hugolib/config.go5
-rw-r--r--hugolib/hugo_sites_build_test.go29
-rw-r--r--hugolib/page__meta.go14
-rw-r--r--hugolib/page__per_output.go18
-rw-r--r--hugolib/page_test.go168
-rw-r--r--hugolib/shortcode_test.go12
-rw-r--r--hugolib/site_benchmark_new_test.go2
-rw-r--r--hugolib/site_test.go22
-rw-r--r--hugolib/testhelpers_test.go4
-rw-r--r--markup/asciidoc/convert.go7
-rw-r--r--markup/blackfriday/blackfriday_config/config.go70
-rw-r--r--markup/blackfriday/convert.go43
-rw-r--r--markup/blackfriday/convert_test.go31
-rw-r--r--markup/blackfriday/renderer.go5
-rw-r--r--markup/converter/converter.go37
-rw-r--r--markup/goldmark/convert.go233
-rw-r--r--markup/goldmark/convert_test.go219
-rw-r--r--markup/goldmark/goldmark_config/config.go74
-rw-r--r--markup/goldmark/toc.go102
-rw-r--r--markup/goldmark/toc_test.go76
-rw-r--r--markup/highlight/config.go188
-rw-r--r--markup/highlight/config_test.go59
-rw-r--r--markup/highlight/highlight.go132
-rw-r--r--markup/highlight/highlight_test.go87
-rw-r--r--markup/highlight/temphighlighting/highlighting.go512
-rw-r--r--markup/highlight/temphighlighting/highlighting_test.go335
-rw-r--r--markup/internal/blackfriday.go108
-rw-r--r--markup/markup.go64
-rw-r--r--markup/markup_config/config.go105
-rw-r--r--markup/markup_config/config_test.go69
-rw-r--r--markup/markup_test.go22
-rw-r--r--markup/mmark/convert.go32
-rw-r--r--markup/mmark/convert_test.go13
-rw-r--r--markup/mmark/renderer.go14
-rw-r--r--markup/org/convert.go7
-rw-r--r--markup/pandoc/convert.go7
-rw-r--r--markup/rst/convert.go8
-rw-r--r--markup/tableofcontents/tableofcontents.go148
-rw-r--r--markup/tableofcontents/tableofcontents_test.go119
-rw-r--r--parser/lowercase_camel_json.go51
-rw-r--r--tpl/transform/remarshal.go58
-rw-r--r--tpl/transform/remarshal_test.go18
-rw-r--r--tpl/transform/transform.go2
-rw-r--r--tpl/transform/transform_test.go2
69 files changed, 3421 insertions, 1665 deletions
diff --git a/commands/genchromastyles.go b/commands/genchromastyles.go
index a2231e56e..1f82d764e 100644
--- a/commands/genchromastyles.go
+++ b/commands/genchromastyles.go
@@ -68,7 +68,7 @@ func (g *genChromaStyles) generate() error {
if err != nil {
return err
}
- formatter := html.New(html.WithClasses())
+ formatter := html.New(html.WithClasses(true))
formatter.WriteCSS(os.Stdout, style)
return nil
}
diff --git a/docs/config.toml b/docs/config.toml
index 6f66955ba..2170b20c4 100644
--- a/docs/config.toml
+++ b/docs/config.toml
@@ -15,18 +15,6 @@ pluralizeListTitles = false
# We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below).
disableAliases = true
-# Highlighting config (Pygments)
-# It is (currently) not in use, but you can do ```go in a content file if you want to.
-pygmentsCodeFences = true
-
-pygmentsOptions = ""
-# Use the Chroma stylesheet
-pygmentsUseClasses = true
-pygmentsUseClassic = false
-
-# See https://help.farbox.com/pygments.html
-pygmentsStyle = "trac"
-
[module]
[module.hugoVersion]
min = "0.56.0"
diff --git a/docs/config/_default/config.toml b/docs/config/_default/config.toml
index 9f908c9fd..ec0a08f56 100644
--- a/docs/config/_default/config.toml
+++ b/docs/config/_default/config.toml
@@ -14,17 +14,11 @@ pluralizeListTitles = false
# We do redirects via Netlify's _redirects file, generated by Hugo (see "outputs" below).
disableAliases = true
-# Highlighting config (Pygments)
-# It is (currently) not in use, but you can do ```go in a content file if you want to.
-pygmentsCodeFences = true
-
-pygmentsOptions = ""
-# Use the Chroma stylesheet
-pygmentsUseClasses = true
-pygmentsUseClassic = false
-
-# See https://help.farbox.com/pygments.html
-pygmentsStyle = "trac"
+[markup]
+[markup.highlight]
+style = "trac"
+lineNumbersInTable = true
+noClasses = false
[outputs]
home = [ "HTML", "RSS", "REDIR", "HEADERS" ]
diff --git a/docs/content/en/about/features.md b/docs/content/en/about/features.md
index cadcc6b0f..a1e741ac0 100644
--- a/docs/content/en/about/features.md
+++ b/docs/content/en/about/features.md
@@ -52,7 +52,7 @@ toc: true
* Integrated [Google Analytics][] support
* Automatic [RSS][] creation
* Support for [Go][], [Amber], and [Ace][] HTML templates
-* [Syntax highlighting][] powered by [Chroma][] (partly compatible with Pygments)
+* [Syntax highlighting][] powered by [Chroma][]
[Ace]: /templates/alternatives/
diff --git a/docs/content/en/content-management/formats.md b/docs/content/en/content-management/formats.md
index a0ed992f2..ea0568616 100644
--- a/docs/content/en/content-management/formats.md
+++ b/docs/content/en/content-management/formats.md
@@ -1,6 +1,6 @@
---
-title: Supported Content Formats
-linktitle: Supported Content Formats
+title: Content Formats
+linktitle: Content Formats
description: Both HTML and Markdown are supported content formats.
date: 2017-01-10
publishdate: 2017-01-10
@@ -13,191 +13,37 @@ menu:
weight: 20
weight: 20 #rem
draft: false
-aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/,/tutorials/mathjax/]
+aliases: [/content/markdown-extras/,/content/supported-formats/,/doc/supported-formats/]
toc: true
---
-**Markdown is the main content format** and comes in two flavours: The excellent [Blackfriday project][blackfriday] (name your files `*.md` or set `markup = "markdown"` in front matter) or its fork [Mmark][mmark] (name your files `*.mmark` or set `markup = "mmark"` in front matter), both very fast markdown engines written in Go.
+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.:
-For Emacs users, [go-org](https://github.com/niklasfasching/go-org) provides built-in native support for Org-mode (name your files `*.org` or set `markup = "org"` in front matter)
+* Markdown converted to HTML
+* [Shortcodes](/content-management/shortcodes/) processed
+* Layout applied
-But in many situations, plain HTML is what you want. Just name your files with `.html` or `.htm` extension inside your content folder. Note that if you want your HTML files to have a layout, they need front matter. It can be empty, but it has to be there:
+## List of content formats
-```html
----
-title: "This is a content file in HTML"
----
-
-<div>
- <h1>Hello, Hugo!</h1>
-</div>
-```
-
-{{% note "Deeply Nested Lists" %}}
-Before you begin writing your content in markdown, Blackfriday has a known issue [(#329)](https://github.com/russross/blackfriday/issues/329) with handling deeply nested lists. Luckily, there is an easy workaround. Use 4-spaces (i.e., <kbd>tab</kbd>) rather than 2-space indentations.
-{{% /note %}}
-
-## Configure BlackFriday Markdown Rendering
-
-You can configure multiple aspects of Blackfriday as shown in the following list. See the docs on [Configuration][config] for the full list of explicit directions you can give to Hugo when rendering your site.
-
-{{< readfile file="/content/en/readfiles/bfconfig.md" markdown="true" >}}
-
-## Extend Markdown
-
-Hugo provides some convenient methods for extending markdown.
-
-### Task Lists
-
-Hugo supports [GitHub-styled task lists (i.e., TODO lists)][gfmtasks] for the Blackfriday markdown renderer. If you do not want to use this feature, you can disable it in your configuration.
-
-#### Example Task List Input
-
-{{< code file="content/my-to-do-list.md" >}}
-- [ ] a task list item
-- [ ] list syntax required
-- [ ] incomplete
-- [x] completed
-{{< /code >}}
-
-#### Example Task List Output
-
-The preceding markdown produces the following HTML in your rendered website:
-
-```
-<ul class="task-list">
- <li><input type="checkbox" disabled="" class="task-list-item"> a task list item</li>
- <li><input type="checkbox" disabled="" class="task-list-item"> list syntax required</li>
- <li><input type="checkbox" disabled="" class="task-list-item"> incomplete</li>
- <li><input type="checkbox" checked="" disabled="" class="task-list-item"> completed</li>
-</ul>
-```
-
-#### Example Task List Display
-
-The following shows how the example task list will look to the end users of your website. Note that visual styling of lists is up to you. This list has been styled according to [the Hugo Docs stylesheet][hugocss].
-
-- [ ] a task list item
-- [ ] list syntax required
-- [ ] incomplete
-- [x] completed
-
-### Emojis
-
-To add emojis directly to content, set `enableEmoji` to `true` in your [site configuration][config]. To use emojis in templates or shortcodes, see [`emojify` function][].
-
-For a full list of emojis, see the [Emoji cheat sheet][emojis].
-
-### Shortcodes
-
-If you write in Markdown and find yourself frequently embedding your content with raw HTML, Hugo provides built-in shortcodes functionality. This is one of the most powerful features in Hugo and allows you to create your own Markdown extensions very quickly.
-
-See [Shortcodes][sc] for usage, particularly for the built-in shortcodes that ship with Hugo, and [Shortcode Templating][sct] to learn how to build your own.
-
-### Code Blocks
-
-Hugo supports GitHub-flavored markdown's use of triple back ticks, as well as provides a special [`highlight` shortcode][hlsc], and syntax highlights those code blocks natively using *Chroma*. Users also have an option to use *Pygments* instead. See the [Syntax Highlighting][hl] section for details.
-
-## Mmark
-
-Mmark is a [fork of BlackFriday][mmark] and markdown superset that is well suited for writing [IETF documentation][ietf]. You can see examples of the syntax in the [Mmark GitHub repository][mmark] or the full syntax on [Miek Gieben's website][].
-
-### Use Mmark
-
-As Hugo ships with Mmark, using the syntax is as easy as changing the extension of your content files from `.md` to `.mmark`.
-
-In the event that you want to only use Mmark in specific files, you can also define the Mmark syntax in your content's front matter:
-
-```
----
-title: My Post
-date: 2017-04-01
-markup: mmark
----
-```
-
-{{% warning %}}
-Thare are some features not available in Mmark; one example being that shortcodes are not translated when used in an included `.mmark` file ([#3131](https://github.com/gohugoio/hugo/issues/3137)), and `EXTENSION_ABBREVIATION` ([#1970](https://github.com/gohugoio/hugo/issues/1970)) and the aforementioned GFM todo lists ([#2270](https://github.com/gohugoio/hugo/issues/2270)) are not fully supported. Contributions are welcome.
-{{% /warning %}}
-
-## MathJax with Hugo
-
-[MathJax](https://www.mathjax.org/) is a JavaScript library that allows the display of mathematical expressions described via a LaTeX-style syntax in the HTML (or Markdown) source of a web page. As it is a pure a JavaScript library, getting it to work within Hugo is fairly straightforward, but does have some oddities that will be discussed here.
-
-This is not an introduction into actually using MathJax to render typeset mathematics on your website. Instead, this page is a collection of tips and hints for one way to get MathJax working on a website built with Hugo.
-
-### Enable MathJax
-
-The first step is to enable MathJax on pages that you would like to have typeset math. There are multiple ways to do this (adventurous readers can consult the [Loading and Configuring](https://docs.mathjax.org/en/latest/web/configuration.html) section of the MathJax documentation for additional methods of including MathJax), but the easiest way is to use the secure MathJax CDN by include a `<script>` tag for the officially recommended secure CDN ([cdn.js.com](https://cdnjs.com)):
-
-{{< code file="add-mathjax-to-page.html" >}}
-<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
-</script>
-{{< /code >}}
-
-One way to ensure that this code is included in all pages is to put it in one of the templates that live in the `layouts/partials/` directory. For example, I have included this in the bottom of my template `footer.html` because I know that the footer will be included in every page of my website.
-
-### Options and Features
-
-MathJax is a stable open-source library with many features. I encourage the interested reader to view the [MathJax Documentation](https://docs.mathjax.org/en/latest/index.html), specifically the sections on [Basic Usage](http://docs.mathjax.org/en/latest/index.html#basic-usage) and [MathJax Configuration Options](http://docs.mathjax.org/en/latest/index.html#mathjax-configuration-options).
-
-### Issues with Markdown
-
-{{% note %}}
-The following issues with Markdown assume you are using `.md` for content and BlackFriday for parsing. Using [Mmark](#mmark) as your content format will obviate the need for the following workarounds.
-
-When using Mmark with MathJax, use `displayMath: [['$$','$$'], ['\\[','\\]']]`. See the [Mmark `README.md`](https://github.com/miekg/mmark/wiki/Syntax#math-blocks) for more information. In addition to MathJax, Mmark has been shown to work well with [KaTeX](https://github.com/Khan/KaTeX). See this [related blog post from a Hugo user](http://nosubstance.me/post/a-great-toolset-for-static-blogging/).
-{{% /note %}}
-
-After enabling MathJax, any math entered between proper markers (see the [MathJax documentation][mathjaxdocs]) will be processed and typeset in the web page. One issue that comes up, however, with Markdown is that the underscore character (`_`) is interpreted by Markdown as a way to wrap text in `emph` blocks while LaTeX (MathJax) interprets the underscore as a way to create a subscript. This "double speak" of the underscore can result in some unexpected and unwanted behavior.
-
-### Solution
-
-There are multiple ways to remedy this problem. One solution is to simply escape each underscore in your math code by entering `\_` instead of `_`. This can become quite tedious if the equations you are entering are full of subscripts.
-
-Another option is to tell Markdown to treat the MathJax code as verbatim code and not process it. One way to do this is to wrap the math expression inside a `<div>` `</div>` block. Markdown would ignore these sections and they would get passed directly on to MathJax and processed correctly. This works great for display style mathematics, but for inline math expressions the line break induced by the `<div>` is not acceptable. The syntax for instructing Markdown to treat inline text as verbatim is by wrapping it in backticks (`` ` ``). You might have noticed, however, that the text included in between backticks is rendered differently than standard text (on this site these are items highlighted in red). To get around this problem, we could create a new CSS entry that would apply standard styling to all inline verbatim text that includes MathJax code. Below I will show the HTML and CSS source that would accomplish this (note this solution was adapted from [this blog post](http://doswa.com/2011/07/20/mathjax-in-markdown.html)---all credit goes to the original author).
-
-{{< code file="mathjax-markdown-solution.html" >}}
-<script type="text/x-mathjax-config">
-MathJax.Hub.Config({
- tex2jax: {
- inlineMath: [['$','$'], ['\\(','\\)']],
- displayMath: [['$$','$$'], ['\[','\]']],
- processEscapes: true,
- processEnvironments: true,
- skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
- TeX: { equationNumbers: { autoNumber: "AMS" },
- extensions: ["AMSmath.js", "AMSsymbols.js"] }<