From bfb9613a14ab2d93a4474e5486d22e52a9d5e2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 6 Nov 2019 20:10:47 +0100 Subject: [PATCH] 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 --- commands/genchromastyles.go | 2 +- docs/config.toml | 12 - docs/config/_default/config.toml | 16 +- docs/content/en/about/features.md | 2 +- docs/content/en/content-management/formats.md | 198 +------ .../content-management/syntax-highlighting.md | 187 +++---- docs/content/en/contribute/documentation.md | 1 + docs/content/en/functions/highlight.md | 6 +- .../getting-started/configuration-markup.md | 73 +++ .../en/getting-started/configuration.md | 48 +- docs/content/en/getting-started/installing.md | 6 - docs/content/en/readfiles/bfconfig.md | 197 ------- .../en/templates/shortcode-templates.md | 4 - docs/data/docs.json | 167 +++++- docs/layouts/shortcodes/code-toggle.html | 34 ++ docs/layouts/shortcodes/new-in.html | 8 + docs/requirements.txt | 1 - go.mod | 3 +- go.sum | 8 +- helpers/content.go | 45 +- helpers/general.go | 27 - helpers/general_test.go | 13 +- helpers/pygments.go | 402 -------------- helpers/pygments_test.go | 300 ---------- hugolib/case_insensitive_test.go | 1 - hugolib/config.go | 5 - hugolib/hugo_sites_build_test.go | 29 +- hugolib/page__meta.go | 14 +- hugolib/page__per_output.go | 18 +- hugolib/page_test.go | 168 +++++- hugolib/shortcode_test.go | 12 + hugolib/site_benchmark_new_test.go | 2 +- hugolib/site_test.go | 22 +- hugolib/testhelpers_test.go | 4 +- markup/asciidoc/convert.go | 7 +- .../blackfriday/blackfriday_config/config.go | 70 +++ markup/blackfriday/convert.go | 43 +- markup/blackfriday/convert_test.go | 31 +- markup/blackfriday/renderer.go | 5 +- markup/converter/converter.go | 37 +- markup/goldmark/convert.go | 233 ++++++++ markup/goldmark/convert_test.go | 219 ++++++++ markup/goldmark/goldmark_config/config.go | 74 +++ markup/goldmark/toc.go | 102 ++++ markup/goldmark/toc_test.go | 76 +++ markup/highlight/config.go | 188 +++++++ markup/highlight/config_test.go | 59 ++ markup/highlight/highlight.go | 132 +++++ markup/highlight/highlight_test.go | 87 +++ .../temphighlighting/highlighting.go | 512 ++++++++++++++++++ .../temphighlighting/highlighting_test.go | 335 ++++++++++++ markup/internal/blackfriday.go | 108 ---- markup/markup.go | 64 ++- markup/markup_config/config.go | 105 ++++ markup/markup_config/config_test.go | 69 +++ markup/markup_test.go | 22 +- markup/mmark/convert.go | 32 +- markup/mmark/convert_test.go | 13 +- markup/mmark/renderer.go | 14 +- markup/org/convert.go | 7 +- markup/pandoc/convert.go | 7 +- markup/rst/convert.go | 8 +- markup/tableofcontents/tableofcontents.go | 148 +++++ .../tableofcontents/tableofcontents_test.go | 119 ++++ parser/lowercase_camel_json.go | 51 ++ tpl/transform/remarshal.go | 58 +- tpl/transform/remarshal_test.go | 18 +- tpl/transform/transform.go | 2 +- tpl/transform/transform_test.go | 2 +- 69 files changed, 3424 insertions(+), 1668 deletions(-) create mode 100644 docs/content/en/getting-started/configuration-markup.md delete mode 100644 docs/content/en/readfiles/bfconfig.md create mode 100644 docs/layouts/shortcodes/code-toggle.html create mode 100644 docs/layouts/shortcodes/new-in.html delete mode 100644 docs/requirements.txt delete mode 100644 helpers/pygments.go delete mode 100644 helpers/pygments_test.go create mode 100644 markup/blackfriday/blackfriday_config/config.go create mode 100644 markup/goldmark/convert.go create mode 100644 markup/goldmark/convert_test.go create mode 100644 markup/goldmark/goldmark_config/config.go create mode 100644 markup/goldmark/toc.go create mode 100644 markup/goldmark/toc_test.go create mode 100644 markup/highlight/config.go create mode 100644 markup/highlight/config_test.go create mode 100644 markup/highlight/highlight.go create mode 100644 markup/highlight/highlight_test.go create mode 100644 markup/highlight/temphighlighting/highlighting.go create mode 100644 markup/highlight/temphighlighting/highlighting_test.go delete mode 100644 markup/internal/blackfriday.go create mode 100644 markup/markup_config/config.go create mode 100644 markup/markup_config/config_test.go create mode 100644 markup/tableofcontents/tableofcontents.go create mode 100644 markup/tableofcontents/tableofcontents_test.go create mode 100644 parser/lowercase_camel_json.go 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" ---- +The current list of content formats in Hugo: -
-

Hello, Hugo!

-
-``` +| Name | Markup identifiers | Comment | +| ------------- | ------------- |-------------| +| Goldmark | md, markdown, goldmark |Note that you can set the default handler of `md` and `markdown` to something else, see [Configure Markup](/getting-started/configuration-markup/).{{< new-in "0.60.0" >}} | +| Blackfriday | blackfriday |Blackfriday will eventually be deprecated.| +|MMark|mmark|Mmark is deprecated and will be removed in a future release.| +|Emacs Org-Mode|org|See [go-org](https://github.com/niklasfasching/go-org).| +|Asciidoc|asciidoc, adoc, ad|Needs Asciidoc or [Asciidoctor][ascii] installed.| +|RST|rst|Needs [RST](http://docutils.sourceforge.net/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. If not, it will be copied as-is.| -{{% 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., tab) rather than 2-space indentations. -{{% /note %}} +The `markup identifier` is fetched from either the `markup` variable in front matter or from the file extension. For markup-related configuration, see [Configure Markup](/getting-started/configuration-markup/). -## 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. +## External Helpers -{{< 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: - -``` - -``` - -#### 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 ` -{{< /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 `
` `
` 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 `
` 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" >}} - -{{< /code >}} - -As before, this content should be included in the HTML source of each page that will be using MathJax. The next code snippet contains the CSS that is used to have verbatim MathJax blocks render with the same font style as the body of the page. - -{{< code file="mathjax-style.css" >}} -code.has-jax { - font: inherit; - font-size: 100%; - background: inherit; - border: inherit; - color: #515151; -} -{{< /code >}} - -In the CSS snippet, notice the line `color: #515151;`. `#515151` is the value assigned to the `color` attribute of the `body` class in my CSS. In order for the equations to fit in with the body of a web page, this value should be the same as the color of the body. - -### Usage - -With this setup, everything is in place for a natural usage of MathJax on pages generated using Hugo. In order to include inline mathematics, just put LaTeX code in between `` `$ TeX Code $` `` or `` `\( TeX Code \)` ``. To include display style mathematics, just put LaTeX code in between `
$$TeX Code$$
`. All the math will be properly typeset and displayed within your Hugo generated web page! - -## Additional Formats Through External Helpers - -Hugo has a new concept called _external helpers_. It means that you can write your content using [Asciidoc][ascii], [reStructuredText][rest], or [pandoc]. If you have files with associated extensions, Hugo will call external commands to generate the content. ([See the Hugo source code for external helpers][helperssource].) - -For example, for Asciidoc files, Hugo will try to call the `asciidoctor` or `asciidoc` command. This means that you will have to install the associated tool on your machine to be able to use these formats. ([See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/)). - -To use these formats, just use the standard extension and the front matter exactly as you would do with natively supported `.md` files. +Some of the formats in the table above needs external helpers installed on your PC. For example, for Asciidoc files, Hugo will try to call the `asciidoctor` or `asciidoc` command. This means that you will have to install the associated tool on your machine to be able to use these formats. ([See the Asciidoctor docs for installation instructions](https://asciidoctor.org/docs/install-toolchain/)). Hugo passes reasonable default arguments to these external helpers by default: diff --git a/docs/content/en/content-management/syntax-highlighting.md b/docs/content/en/content-management/syntax-highlighting.md index 6b277365f..a4359e05d 100644 --- a/docs/content/en/content-management/syntax-highlighting.md +++ b/docs/content/en/content-management/syntax-highlighting.md @@ -3,7 +3,7 @@ title: Syntax Highlighting description: Hugo comes with really fast syntax highlighting from Chroma. date: 2017-02-01 publishdate: 2017-02-01 -keywords: [highlighting,pygments,chroma,code blocks,syntax] +keywords: [highlighting,chroma,code blocks,syntax] categories: [content management] menu: docs: @@ -16,17 +16,39 @@ aliases: [/extras/highlighting/,/extras/highlight/,/tools/syntax-highlighting/] toc: true --- -From Hugo 0.28, the default syntax highlighter in Hugo is [Chroma](https://github.com/alecthomas/chroma); it is built in Go and is really, really fast -- and for the most important parts compatible with Pygments. -If you want to continue to use Pygments (see below), set `pygmentsUseClassic=true` in your site config. +Hugo uses [Chroma](https://github.com/alecthomas/chroma) as its code highlighter; it is built in Go and is really, really fast -- and for the most important parts compatible with Pygments we used before. -The example below shows a simple code snippet from the Hugo source highlighted with the `highlight` shortcode. Note that the gohugo.io site is generated with `pygmentsUseClasses=true` (see [Generate Syntax Highlighter CSS](#generate-syntax-highlighter-css)). +## Configure Syntax Highlighter -* `linenos=inline` or `linenos=table` (`table` will give copy-and-paste friendly code blocks) turns on line numbers. -* `hl_lines` lists a set of line numbers or line number ranges to be highlighted. Note that the hyphen range syntax is only supported for Chroma. +See [Configure Highlight](/getting-started/configuration-markup#highlight). + + +## Generate Syntax Highlighter CSS + +If you run with `pygmentsUseClasses=true` in your site config, you need a style sheet. + +You can generate one with Hugo: + +```bash +hugo gen chromastyles --style=monokai > syntax.css +``` + +Run `hugo gen chromastyles -h` for more options. See https://xyproto.github.io/splash/docs/ for a gallery of available styles. + + +## Highlight Shortcode + +Highlighting is carried out via the [built-in shortcode](/content-management/shortcodes/) `highlight`. `highlight` takes exactly one required parameter for the programming language to be highlighted and requires a closing shortcode. Note that `highlight` is *not* used for client-side javascript highlighting. + +Options: + +* `linenos`: Valid values are `true`, `false`, `table`, `inline`. `table` will give copy-and-paste friendly code blocks) turns on line numbers. +* Setting `linenos` to `false` will turn off linenumbers if it's configured to be on in site config.{{< new-in "0.60.0" >}} +* `hl_lines` lists a set of line numbers or line number ranges to be highlighted. * `linenostart=199` starts the line number count from 199. -With that, this: +### Example: Highlight Shortcode ``` {{}} @@ -62,134 +84,63 @@ func GetTitleFunc(style string) func(s string) string { {{< / highlight >}} -## Configure Syntax Highlighter -To make the transition from Pygments to Chroma seamless, they share a common set of configuration options: - -pygmentsOptions -: A comma separated list of options. See below for a full list. - -pygmentsCodeFences -: Set to true to enable syntax highlighting in code fences with a language tag in markdown (see below for an example). - -pygmentsStyle -: The style of code highlighting. Note that this option is not - relevant when `pygmentsUseClasses` is set. - - Syntax highlighting galleries: - **Chroma** ([short snippets](https://xyproto.github.io/splash/docs/all.html), - [long snippets](https://xyproto.github.io/splash/docs/longer/all.html)), - [Pygments](https://help.farbox.com/pygments.html) - -pygmentsUseClasses -: Set to `true` to use CSS classes to format your highlighted code. See [Generate Syntax Highlighter CSS](#generate-syntax-highlighter-css). - -pygmentsCodeFencesGuessSyntax -: Set to `true` to try to do syntax highlighting on code fenced blocks in markdown without a language tag. - -pygmentsUseClassic -: Set to true to use Pygments instead of the much faster Chroma. - -### Options - -`pygmentsOptions` can be set either in site config or overridden per code block in the Highlight shortcode or template func. - -noclasses -: Use inline style. - -linenos -: For Chroma, any value in this setting will print line numbers. Pygments has some more fine grained control. - -linenostart -: Start the line numbers from this value (default is 1). - - -hl_lines -: Highlight a space separated list of line numbers. For Chroma, you can provide a list of ranges, i.e. "3-8 10-20". - - -The full set of supported options for Pygments is: `encoding`, `outencoding`, `nowrap`, `full`, `title`, `style`, `noclasses`, `classprefix`, `cssclass`, `cssstyles`, `prestyles`, `linenos`, `hl_lines`, `linenostart`, `linenostep`, `linenospecial`, `nobackground`, `lineseparator`, `lineanchors`, `linespans`, `anchorlinenos`, `startinline`. See the [Pygments HTML Formatter Documentation](http://pygments.org/docs/formatters/#HtmlFormatter) for details. - - -## Generate Syntax Highlighter CSS - -If you run with `pygmentsUseClasses=true` in your site config, you need a style sheet. - -You can generate one with Hugo: - -```bash -hugo gen chromastyles --style=monokai > syntax.css -``` - -Run `hugo gen chromastyles -h` for more options. See https://xyproto.github.io/splash/docs/ for a gallery of available styles. - - -## Highlight Shortcode - -Highlighting is carried out via the [built-in shortcode](/content-management/shortcodes/) `highlight`. `highlight` takes exactly one required parameter for the programming language to be highlighted and requires a closing shortcode. Note that `highlight` is *not* used for client-side javascript highlighting. - -### Example `highlight` Shortcode - -{{< code file="example-highlight-shortcode-input.md" >}} -{{}} -
-
-

{{ .Title }}

- {{ range .Pages }} - {{ .Render "summary"}} - {{ end }} -
-
-{{}} -{{< /code >}} - - ## Highlight Template Func See [Highlight](/functions/highlight/). -## Highlight in Code Fences +## Highlighting in Code Fences -It is also possible to add syntax highlighting with GitHub flavored code fences. To enable this, set the `pygmentsCodeFences` to `true` in Hugo's [configuration file](/getting-started/configuration/); +Highlighting in code fences is enabled by default.{{< new-in "0.60.0" >}} ```` -```go-html-template -
-
-

{{ .Title }}

- {{ range .Pages }} - {{ .Render "summary"}} - {{ end }} -
-
+```go-html-template{hl_lines=[3,"5-6"],linenos=true} ``` ```` +```` +```go {linenos=table,hl_lines=[8,"15-17"],linenostart=199} +// ... code +```` + + +Gives this: + +```go {linenos=table,hl_lines=[8,"15-17"],linenostart=199} +// GetTitleFunc returns a func that can be used to transform a string to +// title case. +// +// The supported styles are +// +// - "Go" (strings.Title) +// - "AP" (see https://www.apstylebook.com/) +// - "Chicago" (see https://www.chicagomanualofstyle.org/home.html) +// +// If an unknown or empty style is provided, AP style is what you get. +func GetTitleFunc(style string) func(s string) string { + switch strings.ToLower(style) { + case "go": + return strings.Title + case "chicago": + tc := transform.NewTitleConverter(transform.ChicagoStyle) + return tc.Title + default: + tc := transform.NewTitleConverter(transform.APStyle) + return tc.Title + } +} +``` + +{{< new-in "0.60.0" >}}Note that only Goldmark supports passing attributes such as `hl_lines`, and it's important that it does not contain any spaces. See [goldmark-highlighting](https://github.com/yuin/goldmark-highlighting) for more information. + +The options are the same as in the [highlighting shortcode](/content-management/syntax-highlighting/#highlight-shortcode),including `linenos=false`, but note the slightly different Markdown attribute syntax. + ## List of Chroma Highlighting Languages The full list of Chroma lexers and their aliases (which is the identifier used in the `highlight` template func or when doing highlighting in code fences): {{< chroma-lexers >}} -## Highlight with Pygments Classic - -If you for some reason don't want to use the built-in Chroma highlighter, you can set `pygmentsUseClassic=true` in your config and add Pygments to your path. - -{{% note "Disclaimers on Pygments" %}} -* Pygments is relatively slow and _causes a performance hit when building your site_, but Hugo has been designed to cache the results to disk. -* The caching can be turned off by setting the `--ignoreCache` flag to `true`. -* The languages available for highlighting depend on your Pygments installation. -{{% /note %}} - -If you have never worked with Pygments before, here is a brief primer: - -+ Install Python from [python.org](https://www.python.org/downloads/). Version 2.7.x is already sufficient. -+ Run `pip install Pygments` in order to install Pygments. Once installed, Pygments gives you a command `pygmentize`. Make sure it sits in your PATH; otherwise, Hugo will not be able to find and use it. - -On Debian and Ubuntu systems, you may also install Pygments by running `sudo apt-get install python3-pygments`. - - - [Prism]: https://prismjs.com [prismdownload]: https://prismjs.com/download.html [Highlight.js]: https://highlightjs.org/ diff --git a/docs/content/en/contribute/documentation.md b/docs/content/en/contribute/documentation.md index a85245b06..c4bbbd8bb 100644 --- a/docs/content/en/contribute/documentation.md +++ b/docs/content/en/contribute/documentation.md @@ -104,6 +104,7 @@ Your options for languages are `xml`/`html`, `go`/`golang`, `md`/`markdown`/`mkd ``` ```` + ### Code Block Shortcode The Hugo documentation comes with a very robust shortcode for adding interactive code blocks. diff --git a/docs/content/en/functions/highlight.md b/docs/content/en/functions/highlight.md index f0845227d..1740742ce 100644 --- a/docs/content/en/functions/highlight.md +++ b/docs/content/en/functions/highlight.md @@ -1,7 +1,7 @@ --- title: highlight linktitle: highlight -description: Takes a string of code and language declaration and uses Pygments to return syntax-highlighted HTML with inline-styles. +description: Takes a string of code and language declaration and uses Chroma to return syntax-highlighted HTML. godocref: date: 2017-02-01 publishdate: 2017-02-01 @@ -10,7 +10,7 @@ categories: [functions] menu: docs: parent: "functions" -keywords: [highlighting,pygments,code blocks,syntax] +keywords: [highlighting,code blocks,syntax] signature: ["highlight INPUT LANG OPTIONS"] workson: [] hugoversion: @@ -20,8 +20,6 @@ deprecated: false [`highlight` is used in Hugo's built-in `highlight` shortcode][highlight]. -See [Installing Hugo][installpygments] for more information on Pygments or [Syntax Highlighting][syntax] for more options on how to add syntax highlighting to your code blocks with Hugo. - [highlight]: /content-management/shortcodes/#highlight [installpygments]: /getting-started/installing/#installing-pygments-optional diff --git a/docs/content/en/getting-started/configuration-markup.md b/docs/content/en/getting-started/configuration-markup.md new file mode 100644 index 000000000..2a24fcdd0 --- /dev/null +++ b/docs/content/en/getting-started/configuration-markup.md @@ -0,0 +1,73 @@ +--- +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/). + +### 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. \ No newline at end of file diff --git a/docs/content/en/getting-started/configuration.md b/docs/content/en/getting-started/configuration.md index 4fea87723..a653c0e0b 100644 --- a/docs/content/en/getting-started/configuration.md +++ b/docs/content/en/getting-started/configuration.md @@ -184,11 +184,14 @@ log (false) logFile ("") : Log File path (if set, logging enabled automatically). +markup +: See [Configure Markup](/getting-started/configuration-markup).{{< new-in "0.60.0" >}} + menu : See [Add Non-content Entries to a Menu](/content-management/menus/#add-non-content-entries-to-a-menu). module -: Module config see [Module Config](/hugo-modules/configuration/). +: Module config see [Module Config](/hugo-modules/configuration/).{{< new-in "0.56.0" >}} newContentEditor ("") : The editor to use when creating new content. @@ -214,26 +217,8 @@ pluralizeListTitles (true) publishDir ("public") : The directory to where Hugo will write the final static site (the HTML files etc.). -pygmentsOptions ("") -: A comma separated list of options for syntax highlighting. See the [Syntax Highlighting Options](/content-management/syntax-highlighting/#options) for the full list of available options. - -pygmentsCodeFences (false) -: Enables syntax highlighting in [code fences with a language tag](/content-management/syntax-highlighting/#highlight-in-code-fences) in markdown. - -pygmentsCodeFencesGuessSyntax (false) -: Enable syntax guessing for code fences without specified language. - -pygmentsStyle ("monokai") -: Color-theme or style for syntax highlighting. See [Pygments Color Themes](https://help.farbox.com/pygments.html). - -pygmentsUseClasses (false) -: Enable using external CSS for syntax highlighting. - -pygmentsUseClassic (false) -: Enable using Pygments instead of the much faster Chroma for syntax highlighting. - related -: See [Related Content](/content-management/related/#configure-related-content). +: See [Related Content](/content-management/related/#configure-related-content).{{< new-in "0.27" >}} relativeURLs (false) : Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs. @@ -436,29 +421,6 @@ The above will try first to extract the value for `.Date` from the filename, the `:git` : This is the Git author date for the last revision of this content file. This will only be set if `--enableGitInfo` is set or `enableGitInfo = true` is set in site config. -## Configure Blackfriday - -[Blackfriday](https://github.com/russross/blackfriday) is Hugo's built-in Markdown rendering engine. - -Hugo typically configures Blackfriday with sane default values that should fit most use cases reasonably well. - -However, if you have specific needs with respect to Markdown, Hugo exposes some of its Blackfriday behavior options for you to alter. The following table lists these Hugo options, paired with the corresponding flags from Blackfriday's source code ( [html.go](https://github.com/russross/blackfriday/blob/master/html.go) and [markdown.go](https://github.com/russross/blackfriday/blob/master/markdown.go)). - -{{< readfile file="/content/en/readfiles/bfconfig.md" markdown="true" >}} - -{{% note %}} -1. Blackfriday flags are *case sensitive* as of Hugo v0.15. -2. Blackfriday flags must be grouped under the `blackfriday` key and can be set on both the site level *and* the page level. Any setting on a page will override its respective site setting. -{{% /note %}} - -{{< code-toggle file="config" >}} -[blackfriday] - angledQuotes = true - fractions = false - plainIDAnchors = true - extensions = ["hardLineBreak"] -{{< /code-toggle >}} - ## Configure Additional Output Formats Hugo v0.20 introduced the ability to render your content to multiple output formats (e.g., to JSON, AMP html, or CSV). See [Output Formats][] for information on how to add these values to your Hugo project's configuration file. diff --git a/docs/content/en/getting-started/installing.md b/docs/content/en/getting-started/installing.md index bffbb777e..f388188b2 100644 --- a/docs/content/en/getting-started/installing.md +++ b/docs/content/en/getting-started/installing.md @@ -502,12 +502,6 @@ OpenBSD provides a package for Hugo via `pkg_add`: Upgrading Hugo is as easy as downloading and replacing the executable you’ve placed in your `PATH` or run `brew upgrade hugo` if using Homebrew. -## Install Pygments (Optional) - -The Hugo executable has one *optional* external dependency for source code highlighting ([Pygments][pygments]). - -If you want to have source code highlighting using the [highlight shortcode][], you need to install the Python-based Pygments program. The procedure is outlined on the [Pygments homepage][pygments]. - ## Next Steps Now that you've installed Hugo, read the [Quick Start guide][quickstart] and explore the rest of the documentation. If you have questions, ask the Hugo community directly by visiting the [Hugo Discussion Forum][forum]. diff --git a/docs/content/en/readfiles/bfconfig.md b/docs/content/en/readfiles/bfconfig.md deleted file mode 100644 index 95941234d..000000000 --- a/docs/content/en/readfiles/bfconfig.md +++ /dev/null @@ -1,197 +0,0 @@ -## Blackfriday Options - -`taskLists` -: default: **`true`**
- Blackfriday flag:
- Purpose: `false` turns off GitHub-style automatic task/TODO list generation. - -`smartypants` -: default: **`true`**
- Blackfriday flag: **`HTML_USE_SMARTYPANTS`**
- Purpose: `false` disables smart punctuation substitutions, including smart quotes, smart dashes, smart fractions, etc. If `true`, it may be fine-tuned with the `angledQuotes`, `fractions`, `smartDashes`, and `latexDashes` flags (see below). - -`smartypantsQuotesNBSP` -: default: **`false`**
- Blackfriday flag: **`HTML_SMARTYPANTS_QUOTES_NBSP`**
- Purpose: `true` enables French style Guillemets with non-breaking space inside the quotes. - -`angledQuotes` -: default: **`false`**
- Blackfriday flag: **`HTML_SMARTYPANTS_ANGLED_QUOTES`**
- Purpose: `true` enables smart, angled double quotes. Example: "Hugo" renders to «Hugo» instead of “Hugo”. - -`fractions` -: default: **`true`**
- Blackfriday flag: **`HTML_SMARTYPANTS_FRACTIONS`**
- Purpose: false disables smart fractions.
- Example: `5/12` renders to 512(<sup>5</sup>&frasl;<sub>12</sub>).
Caveat: Even with fractions = false, Blackfriday still converts `1/2`, `1/4`, and `3/4` respectively to ½ (&frac12;), ¼ (&frac14;) and ¾ (&frac34;), but only these three. - -`smartDashes` -: default: **`true`**
- Blackfriday flag: **`HTML_SMARTY_DASHES`**
- Purpose: `false` disables smart dashes; i.e., the conversion of multiple hyphens into an en-dash or em-dash. If `true`, its behavior can be modified with the `latexDashes` flag below. - -`latexDashes` -: default: **`true`**
- Blackfriday flag: **`HTML_SMARTYPANTS_LATEX_DASHES`**
- Purpose: `false` disables LaTeX-style smart dashes and selects conventional smart dashes. Assuming `smartDashes`:
- If `true`, `--` is translated into – (`–`), whereas `---` is translated into — (`—`).
- However, *spaced* single hyphen between two words is translated into an en dash— e.g., "`12 June - 3 July`" becomes `12 June – 3 July` upon rendering. - -`hrefTargetBlank` -: default: **`false`**
- Blackfriday flag: **`HTML_HREF_TARGET_BLANK`**
- Purpose: `true` opens external links **absolute** links in a new window or tab. While the `target="_blank"` attribute is typically used for external links, Blackfriday does that for _all_ absolute links ([ref](https://discourse.gohugo.io/t/internal-links-in-same-tab-external-links-in-new-tab/11048/8)). One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting `canonifyURLs` to `true` or via `absURL`). - -`nofollowLinks` -: default: **`false`**
- Blackfriday flag: **`HTML_NOFOLLOW_LINKS`**
- Purpose: `true` creates external links **absolute** links with `nofollow` being added to their `rel` attribute. Thereby crawlers are advised to not follow the link. While the `rel="nofollow"` attribute is typically used for external links, Blackfriday does that for _all_ absolute links. One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting `canonifyURLs` to `true` or via `absURL`). - -`noreferrerLinks` -: default: **`false`**
- Blackfriday flag: **`HTML_NOREFERRER_LINKS`**
- Purpose: `true` creates external links **absolute** links with `noreferrer` being added to their `rel` attribute. Thus when following the link no referrer information will be leaked. While the `rel="noreferrer"` attribute is typically used for external links, Blackfriday does that for _all_ absolute links. One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting `canonifyURLs` to `true` or via `absURL`). - -`plainIDAnchors` -: default **`true`**
- Blackfriday flag: **`FootnoteAnchorPrefix` and `HeaderIDSuffix`**
- Purpose: `true` renders any heading and footnote IDs without the document ID.
- Example: renders `#my-heading` instead of `#my-heading:bec3ed8ba720b970` - -`extensions` -: default: **`[]`**
- Purpose: Enable one or more Blackfriday's Markdown extensions (**`EXTENSION_*`**).
- Example: Include `hardLineBreak` in the list to enable Blackfriday's `EXTENSION_HARD_LINE_BREAK`.
- *See [Blackfriday extensions](#blackfriday-extensions) section for information on all extensions.* - -`extensionsmask` -: default: **`[]`**
- Purpose: Disable one or more of Blackfriday's Markdown extensions (**`EXTENSION_*`**).
- Example: Include `autoHeaderIds` as `false` in the list to disable Blackfriday's `EXTENSION_AUTO_HEADER_IDS`.
- *See [Blackfriday extensions](#blackfriday-extensions) section for information on all extensions.* - -`skipHTML` -: default: **`false`**
- Blackfriday flag: **`HTML_SKIP_HTML`**
- Purpose: `true` causes any HTML in the markdown files to be skipped. - -## Blackfriday extensions - -`noIntraEmphasis` -: default: *enabled*
- Purpose: The "\_" character is commonly used inside words when discussing - code, so having Markdown interpret it as an emphasis command is usually the - wrong thing. When enabled, Blackfriday lets you treat all emphasis markers - as normal characters when they occur inside a word. - -`tables` -: default: *enabled*
- Purpose: When enabled, tables can be created by drawing them in the input - using the below syntax: - Example: - - Name | Age - --------|------ - Bob | 27 - Alice | 23 - -`fencedCode` -: default: *enabled*
- Purpose: When enabled, in addition to the normal 4-space indentation to mark - code blocks, you can explicitly mark them and supply a language (to make - syntax highlighting simple). - - You can use 3 or more backticks to mark the beginning of the block, and the - same number to mark the end of the block. - - Example: - - ```md - # Heading Level 1 - Some test - ## Heading Level 2 - Some more test - ``` - -`autolink` -: default: *enabled*
- Purpose: When enabled, URLs that have not been explicitly marked as links - will be converted into links. - -`strikethrough` -: default: *enabled*
- Purpose: When enabled, text wrapped with two tildes will be crossed out.
- Example: `~~crossed-out~~` - -`laxHtmlBlocks` -: default: *disabled*
- Purpose: When enabled, loosen up HTML block parsing rules. - -`spaceHeaders` -: default: *enabled*
- Purpose: When enabled, be strict about prefix header rules. - -`hardLineBreak` -: default: *disabled*
- Purpose: When enabled, newlines in the input translate into line breaks in - the output. - - -`tabSizeEight` -: default: *disabled*
- Purpose: When enabled, expand tabs to eight spaces instead of four. - -`footnotes` -: default: *enabled*
- Purpose: When enabled, Pandoc-style footnotes will be supported. The - footnote marker in the text that will become a superscript text; the - footnote definition will be placed in a list of footnotes at the end of the - document.
- Example: - - This is a footnote.[^1] - - [^1]: the footnote text. - -`noEmptyLineBeforeBlock` -: default: *disabled*
- Purpose: When enabled, no need to insert an empty line to start a (code, - quote, ordered list, unordered list) block. - - -`headerIds` -: default: *enabled*
- Purpose: When enabled, allow specifying header IDs with `{#id}`. - -`titleblock` -: default: *disabled*
- Purpose: When enabled, support [Pandoc-style title blocks][1]. - -`autoHeaderIds` -: default: *enabled*
- Purpose: When enabled, auto-create the header ID's from the headline text. - -`backslashLineBreak` -: default: *enabled*
- Purpose: When enabled, translate trailing backslashes into line breaks. - -`definitionLists` -: default: *enabled*
- Purpose: When enabled, a simple definition list is made of a single-line - term followed by a colon and the definition for that term.
- Example: - - Cat - : Fluffy animal everyone likes - - Internet - : Vector of transmission for pictures of cats - - Terms must be separated from the previous definition by a blank line. - -`joinLines` -: default: *enabled*
- Purpose: When enabled, delete newlines and join the lines. - -[1]: http://pandoc.org/MANUAL.html#extension-pandoc_title_block diff --git a/docs/content/en/templates/shortcode-templates.md b/docs/content/en/templates/shortcode-templates.md index cf34feedc..898296f2b 100644 --- a/docs/content/en/templates/shortcode-templates.md +++ b/docs/content/en/templates/shortcode-templates.md @@ -299,10 +299,6 @@ The rendered output of the HTML example code block will be as follows:
{{< /code >}} -{{% note %}} -The preceding shortcode makes use of a Hugo-specific template function called `highlight`, which uses [Pygments](http://pygments.org) to add syntax highlighting to the example HTML code block. See the [developer tools page on syntax highlighting](/tools/syntax-highlighting/) for more information. -{{% /note %}} - ### Nested Shortcode: Image Gallery Hugo's [`.Parent` shortcode variable][parent] returns a boolean value depending on whether the shortcode in question is called within the context of a *parent* shortcode. This provides an inheritance model for common shortcode parameters. diff --git a/docs/data/docs.json b/docs/data/docs.json index 1c09a788e..0944ab881 100644 --- a/docs/data/docs.json +++ b/docs/data/docs.json @@ -1,6 +1,13 @@ { "chroma": { "lexers": [ + { + "Name": "ABAP", + "Aliases": [ + "ABAP", + "abap" + ] + }, { "Name": "ABNF", "Aliases": [ @@ -134,6 +141,13 @@ "winbatch" ] }, + { + "Name": "BibTeX", + "Aliases": [ + "bib", + "bibtex" + ] + }, { "Name": "BlitzBasic", "Aliases": [ @@ -405,7 +419,8 @@ "Aliases": [ "forth", "frt", - "fs" + "fs", + "fth" ] }, { @@ -579,12 +594,27 @@ "idris" ] }, + { + "Name": "Igor", + "Aliases": [ + "igor", + "igorpro", + "ipf" + ] + }, { "Name": "Io", "Aliases": [ "io" ] }, + { + "Name": "J", + "Aliases": [ + "ijs", + "j" + ] + }, { "Name": "JSON", "Aliases": [ @@ -1342,6 +1372,63 @@ } ] }, + "config": { + "markup": { + "defaultMarkdownHandler": "goldmark", + "highlight": { + "style": "monokai", + "codeFences": true, + "noClasses": true, + "lineNos": false, + "lineNumbersInTable": true, + "lineNoStart": 1, + "hl_Lines": "", + "tabWidth": 4 + }, + "tableOfContents": { + "startLevel": 2, + "endLevel": 3 + }, + "goldmark": { + "renderer": { + "hardWraps": false, + "xHTML": false, + "unsafe": false + }, + "parser": { + "autoHeadingID": true, + "attribute": true + }, + "extensions": { + "typographer": true, + "footnote": true, + "definitionList": true, + "table": true, + "strikethrough": true, + "linkify": true, + "taskList": true + } + }, + "blackFriday": { + "smartypants": true, + "smartypantsQuotesNBSP": false, + "angledQuotes": false, + "fractions": true, + "hrefTargetBlank": false, + "nofollowLinks": false, + "noreferrerLinks": false, + "smartDashes": true, + "latexDashes": true, + "taskLists": true, + "plainIDAnchors": true, + "extensions": null, + "extensionsMask": null, + "skipHTML": false, + "footnoteAnchorPrefix": "", + "footnoteReturnLinkContents": "" + } + } + }, "media": { "types": [ { @@ -1513,6 +1600,68 @@ "suffixes": [ "scss" ] + }, + { + "type": "video/3gpp", + "string": "video/3gpp", + "mainType": "video", + "subType": "3gpp", + "delimiter": ".", + "suffixes": [ + "3gpp", + "3gp" + ] + }, + { + "type": "video/mp4", + "string": "video/mp4", + "mainType": "video", + "subType": "mp4", + "delimiter": ".", + "suffixes": [ + "mp4" + ] + }, + { + "type": "video/mpeg", + "string": "video/mpeg", + "mainType": "video", + "subType": "mpeg", + "delimiter": ".", + "suffixes": [ + "mpg", + "mpeg" + ] + }, + { + "type": "video/ogg", + "string": "video/ogg", + "mainType": "video", + "subType": "ogg", + "delimiter": ".", + "suffixes": [ + "ogv" + ] + }, + { + "type": "video/webm", + "string": "video/webm", + "mainType": "video", + "subType": "webm", + "delimiter": ".", + "suffixes": [ + "webm" + ] + }, + { + "type": "video/x-msvideo", + "string": "video/x-msvideo", + "mainType": "video", + "subType": "x-msvideo", + "delimiter": ".", + "suffixes": [ + "avi" + ] } ] }, @@ -2290,10 +2439,10 @@ ] }, "Eq": { - "Description": "Eq returns the boolean truth of arg1 == arg2.", + "Description": "Eq returns the boolean truth of arg1 == arg2 || arg1 == arg3 || arg1 == arg4.", "Args": [ - "x", - "y" + "first", + "others" ], "Aliases": [ "eq" @@ -2454,7 +2603,7 @@ ] }, "Dictionary": { - "Description": "Dictionary creates a map[string]interface{} from the given parameters by\nwalking the parameters and treating them as key-value pairs. The number\nof parameters must be even.", + "Description": "Dictionary creates a map[string]interface{} from the given parameters by\nwalking the parameters and treating them as key-value pairs. The number\nof parameters must be even.\nThe keys can be string slices, which will create the needed nested structure.", "Args": [ "values" ], @@ -2521,7 +2670,7 @@ "Description": "Index returns the result of indexing its first argument by the following\narguments. Thus \"index x 1 2 3\" is, in Go syntax, x[1][2][3]. Each\nindexed item must be a map, slice, or array.\n\nCopied from Go stdlib src/text/template/funcs.go.\n\nWe deviate from the stdlib due to https://github.com/golang/go/issues/14751.\n\nTODO(moorereason): merge upstream changes.", "Args": [ "item", - "indices" + "args" ], "Aliases": [ "index" @@ -2630,6 +2779,12 @@ ] ] }, + "Reverse": { + "Description": "", + "Args": null, + "Aliases": null, + "Examples": null + }, "Seq": { "Description": "Seq creates a sequence of integers. It's named and used as GNU's seq.\n\nExamples:\n 3 =\u003e 1, 2, 3\n 1 2 4 =\u003e 1, 3\n -3 =\u003e -1, -2, -3\n 1 4 =\u003e 1, 2, 3, 4\n 1 -2 =\u003e 1, 0, -1, -2", "Args": [ diff --git a/docs/layouts/shortcodes/code-toggle.html b/docs/layouts/shortcodes/code-toggle.html new file mode 100644 index 000000000..da4b00719 --- /dev/null +++ b/docs/layouts/shortcodes/code-toggle.html @@ -0,0 +1,34 @@ +{{ $file := .Get "file" }} +{{ $code := "" }} +{{ with .Get "config" }} +{{ $file = $file | default "config" }} +{{ $sections := (split . ".") }} +{{ $configSection := index $.Site.Data.docs.config $sections }} +{{ $code = dict $sections $configSection }} +{{ else }} +{{ $code = $.Inner }} +{{ end }} +{{ $langs := (slice "yaml" "toml" "json") }} +
+
+ {{- with $file -}} +
{{ . }}.
+ {{- end -}} + {{ range $langs }} +   + {{ end }} +
+
+ {{ range $langs }} +
+ {{ highlight ($code | transform.Remarshal . | safeHTML) . ""}} +
+ {{ if ne ($.Get "copy") "false" }} + + {{/* Functionality located within filesaver.js The copy here is located in the css with .copy class so it can be replaced with JS on success */}} + {{end}} + {{ end }} +
+ +
diff --git a/docs/layouts/shortcodes/new-in.html b/docs/layouts/shortcodes/new-in.html new file mode 100644 index 000000000..ab0abb273 --- /dev/null +++ b/docs/layouts/shortcodes/new-in.html @@ -0,0 +1,8 @@ +{{ $version := .Get 0 }} +{{ if not $version }} +{{ errorf "Missing version in new-in shortcode "}} +{{ end }} +{{ $version = $version | strings.TrimPrefix "v" }} + \ No newline at end of file diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index e0f2f62df..000000000 --- a/docs/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Pygments==2.1.3 diff --git a/go.mod b/go.mod index 004dbcd71..42298c5e0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/PuerkitoBio/purell v1.1.0 github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect - github.com/alecthomas/chroma v0.6.9 + github.com/alecthomas/chroma v0.6.10-0.20191121231300-5921c52787e3 github.com/alecthomas/repr v0.0.0-20181024024818-d37bc2a10ba1 // indirect github.com/armon/go-radix v1.0.0 github.com/aws/aws-sdk-go v1.19.40 @@ -54,6 +54,7 @@ require ( github.com/spf13/viper v1.4.0 github.com/tdewolff/minify/v2 v2.5.2 github.com/yosssi/ace v0.0.5 + github.com/yuin/goldmark v1.1.4 go.opencensus.io v0.22.0 // indirect gocloud.dev v0.15.0 golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff diff --git a/go.sum b/go.sum index b6d2b5907..03e231d13 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= -github.com/alecthomas/chroma v0.6.9 h1:afiCdwnNPo6fcyvoqqsXs78t7NbR9TuW4wDB7NJkcag= -github.com/alecthomas/chroma v0.6.9/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY= +github.com/alecthomas/chroma v0.6.10-0.20191121231300-5921c52787e3 h1:7QpewsuR2wMuqAR9SADf+Cb043SlnmlA7LtDJGDx7UQ= +github.com/alecthomas/chroma v0.6.10-0.20191121231300-5921c52787e3/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= @@ -116,8 +116,6 @@ github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8 github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.4.1 h1:Wv2VwvNn73pAdFIVUQRXYDFp31lXKbqblIXo/Q5GPSg= github.com/frankban/quicktest v1.4.1/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ= -github.com/frankban/quicktest v1.5.0 h1:Tb4jWdSpdjKzTUicPnY61PZxKbDoGa7ABbrReT3gQVY= -github.com/frankban/quicktest v1.5.0/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/frankban/quicktest v1.6.0 h1:Cd62nl66vQsx8Uv1t8M0eICyxIwZG7MxiAOrdnnUSW0= github.com/frankban/quicktest v1.6.0/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= @@ -349,6 +347,8 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yosssi/ace v0.0.5 h1:tUkIP/BLdKqrlrPwcmH0shwEEhTRHoGnc1wFIWmaBUA= github.com/yosssi/ace v0.0.5/go.mod h1:ALfIzm2vT7t5ZE7uoIZqF3TQ7SAOyupFZnkrF5id+K0= +github.com/yuin/goldmark v1.1.4 h1:Fj9vOhXMWRBITkIfa8OG/5j6PTKPkyPHxZbT1bvmjV8= +github.com/yuin/goldmark v1.1.4/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.mongodb.org/mongo-driver v1.0.1/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM= go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= diff --git a/helpers/content.go b/helpers/content.go index 357bd48e7..941475461 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -32,7 +32,6 @@ import ( bp "github.com/gohugoio/hugo/bufferpool" "github.com/gohugoio/hugo/config" "github.com/spf13/afero" - jww "github.com/spf13/jwalterweatherman" "strings" ) @@ -58,9 +57,6 @@ type ContentSpec struct { BuildExpired bool BuildDrafts bool - Highlight func(code, lang, optsStr string) (string, error) - defatultPygmentsOpts map[string]string - Cfg config.Provider } @@ -77,36 +73,10 @@ func NewContentSpec(cfg config.Provider, logger *loggers.Logger, contentFs afero Cfg: cfg, } - // Highlighting setup - options, err := parseDefaultPygmentsOpts(cfg) - if err != nil { - return nil, err - } - spec.defatultPygmentsOpts = options - - // Use the Pygmentize on path if present - useClassic := false - h := newHiglighters(spec) - - if cfg.GetBool("pygmentsUseClassic") { - if !hasPygments() { - jww.WARN.Println("Highlighting with pygmentsUseClassic set requires Pygments to be installed and in the path") - } else { - useClassic = true - } - } - - if useClassic { - spec.Highlight = h.pygmentsHighlight - } else { - spec.Highlight = h.chromaHighlight - } - converterProvider, err := markup.NewConverterProvider(converter.ProviderConfig{ Cfg: cfg, ContentFs: contentFs, Logger: logger, - Highlight: spec.Highlight, }) if err != nil { return nil, err @@ -220,6 +190,21 @@ func (c *ContentSpec) RenderMarkdown(src []byte) ([]byte, error) { return b.Bytes(), nil } +func (c *ContentSpec) ResolveMarkup(in string) string { + in = strings.ToLower(in) + switch in { + case "md", "markdown", "mdown": + return "markdown" + case "html", "htm": + return "html" + default: + if conv := c.Converters.Get(in); conv != nil { + return conv.Name() + } + } + return "" +} + // TotalWords counts instance of one or more consecutive white space // characters, as defined by unicode.IsSpace, in s. // This is a cheaper way of word counting than the obvious len(strings.Fields(s)). diff --git a/helpers/general.go b/helpers/general.go index 80c0591b2..259bcf8f4 100644 --- a/helpers/general.go +++ b/helpers/general.go @@ -44,11 +44,6 @@ import ( // FilePathSeparator as defined by os.Separator. const FilePathSeparator = string(filepath.Separator) -// Strips carriage returns from third-party / external processes (useful for Windows) -func normalizeExternalHelperLineFeeds(content []byte) []byte { - return bytes.Replace(content, []byte("\r"), []byte(""), -1) -} - // FindAvailablePort returns an available and valid TCP port. func FindAvailablePort() (*net.TCPAddr, error) { l, err := net.Listen("tcp", ":0") @@ -74,28 +69,6 @@ func InStringArray(arr []string, el string) bool { return false } -// GuessType attempts to guess the type of file from a given string. -func GuessType(in string) string { - switch strings.ToLower(in) { - case "md", "markdown", "mdown": - return "markdown" - case "asciidoc", "adoc", "ad": - return "asciidoc" - case "mmark": - return "mmark" - case "rst": - return "rst" - case "pandoc", "pdc": - return "pandoc" - case "html", "htm": - return "html" - case "org": - return "org" - } - - return "" -} - // FirstUpper returns a string with the first character as upper case. func FirstUpper(s string) string { if s == "" { diff --git a/helpers/general_test.go b/helpers/general_test.go index e5e5e56ed..b8a98fb69 100644 --- a/helpers/general_test.go +++ b/helpers/general_test.go @@ -19,11 +19,20 @@ import ( "strings" "testing" + "github.com/spf13/viper" + + "github.com/gohugoio/hugo/common/loggers" + qt "github.com/frankban/quicktest" "github.com/spf13/afero" ) -func TestGuessType(t *testing.T) { +func TestResolveMarkup(t *testing.T) { + c := qt.New(t) + cfg := viper.New() + spec, err := NewContentSpec(cfg, loggers.NewErrorLogger(), afero.NewMemMapFs()) + c.Assert(err, qt.IsNil) + for i, this := range []struct { in string expect string @@ -43,7 +52,7 @@ func TestGuessType(t *testing.T) { {"org", "org"}, {"excel", ""}, } { - result := GuessType(this.in) + result := spec.ResolveMarkup(this.in) if result != this.expect { t.Errorf("[%d] got %s but expected %s", i, result, this.expect) } diff --git a/helpers/pygments.go b/helpers/pygments.go deleted file mode 100644 index 4d7631ced..000000000 --- a/helpers/pygments.go +++ /dev/null @@ -1,402 +0,0 @@ -// Copyright 2019 The Hugo Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package helpers - -import ( - "bytes" - "crypto/sha1" - "fmt" - "io" - "io/ioutil" - "os/exec" - "path/filepath" - "regexp" - "sort" - "strconv" - "strings" - - "github.com/alecthomas/chroma" - "github.com/alecthomas/chroma/formatters" - "github.com/alecthomas/chroma/formatters/html" - "github.com/alecthomas/chroma/lexers" - "github.com/alecthomas/chroma/styles" - bp "github.com/gohugoio/hugo/bufferpool" - - "github.com/gohugoio/hugo/config" - "github.com/gohugoio/hugo/hugofs" - jww "github.com/spf13/jwalterweatherman" -) - -const pygmentsBin = "pygmentize" - -// hasPygments checks to see if Pygments is installed and available -// on the system. -func hasPygments() bool { - if _, err := exec.LookPath(pygmentsBin); err != nil { - return false - } - return true -} - -type highlighters struct { - cs *ContentSpec - ignoreCache bool - cacheDir string -} - -func newHiglighters(cs *ContentSpec) highlighters { - return highlighters{cs: cs, ignoreCache: cs.Cfg.GetBool("ignoreCache"), cacheDir: cs.Cfg.GetString("cacheDir")} -} - -func (h highlighters) chromaHighlight(code, lang, optsStr string) (string, error) { - opts, err := h.cs.parsePygmentsOpts(optsStr) - if err != nil { - jww.ERROR.Print(err.Error()) - return code, err - } - - style, found := opts["style"] - if !found || style == "" { - style = "friendly" - } - - f, err := h.cs.chromaFormatterFromOptions(opts) - if err != nil { - jww.ERROR.Print(err.Error()) - return code, err - } - - b := bp.GetBuffer() - defer bp.PutBuffer(b) - - err = chromaHighlight(b, code, lang, style, f) - if err != nil { - jww.ERROR.Printf("Highlight failed: %s\nLang: %q\nCode: \n%s", err, lang, code) - return code, err - } - - return h.injectCodeTag(`
`+b.String()+"
", lang), nil -} - -func (h highlighters) pygmentsHighlight(code, lang, optsStr string) (string, error) { - options, err := h.cs.createPygmentsOptionsString(optsStr) - - if err != nil { - jww.ERROR.Print(err.Error()) - return code, nil - } - - // Try to read from cache first - hash := sha1.New() - io.WriteString(hash, code) - io.WriteString(hash, lang) - io.WriteString(hash, options) - - fs := hugofs.Os - - var cachefile string - - if !h.ignoreCache && h.cacheDir != "" { - cachefile = filepath.Join(h.cacheDir, fmt.Sprintf("pygments-%x", hash.Sum(nil))) - - exists, err := Exists(cachefile, fs) - if err != nil { - jww.ERROR.Print(err.Error()) - return code, nil - } - if exists { - f, err := fs.Open(cachefile) - if err != nil { - jww.ERROR.Print(err.Error()) - return code, nil - } - - s, err := ioutil.ReadAll(f) - if err != nil { - jww.ERROR.Print(err.Error()) - return code, nil - } - - return string(s), nil - } - } - - // No cache file, render and cache it - var out bytes.Buffer - var stderr bytes.Buffer - - var langOpt string - if lang == "" { - langOpt = "-g" // Try guessing the language - } else { - langOpt = "-l" + lang - } - - cmd := exec.Command(pygmentsBin, langOpt, "-fhtml", "-O", options) - cmd.Stdin = strings.NewReader(code) - cmd.Stdout = &out - cmd.Stderr = &stderr - - if err := cmd.Run(); err != nil { - jww.ERROR.Print(stderr.String()) - return code, err - } - - str := string(normalizeExternalHelperLineFeeds(out.Bytes())) - - str = h.injectCodeTag(str, lang) - - if !h.ignoreCache && cachefile != "" { - // Write cache file - if err := WriteToDisk(cachefile, strings.NewReader(str), fs); err != nil { - jww.ERROR.Print(stderr.String()) - } - } - - return str, nil -} - -var preRe = regexp.MustCompile(`(?s)(.*?)(.*?)()`) - -func (h highlighters) injectCodeTag(code, lang string) string { - if lang == "" { - return code - } - codeTag := fmt.Sprintf(``, lang, lang) - return preRe.ReplaceAllString(code, fmt.Sprintf("$1%s$2$3", codeTag)) -} - -func chromaHighlight(w io.Writer, source, lexer, style string, f chroma.Formatter) error { - l := lexers.Get(lexer) - if l == nil { - l = lexers.Analyse(source) - } - if l == nil { - l = lexers.Fallback - } - l = chroma.Coalesce(l) - - if f == nil { - f = formatters.Fallback - } - - s := styles.Get(style) - if s == nil { - s = styles.Fallback - } - - it, err := l.Tokenise(nil, source) - if err != nil { - return err - } - - return f.Format(w, s, it) -} - -var pygmentsKeywords = make(map[string]bool) - -func init() { - pygmentsKeywords["encoding"] = true - pygmentsKeywords["outencoding"] = true - pygmentsKeywords["nowrap"] = true - pygmentsKeywords["full"] = true - pygmentsKeywords["title"] = true - pygmentsKeywords["style"] = true - pygmentsKeywords["noclasses"] = true - pygmentsKeywords["classprefix"] = true - pygmentsKeywords["cssclass"] = true - pygmentsKeywords["cssstyles"] = true - pygmentsKeywords["prestyles"] = true - pygmentsKeywords["linenos"] = true - pygmentsKeywords["hl_lines"] = true - pygmentsKeywords["linenostart"] = true - pygmentsKeywords["linenostep"] = true - pygmentsKeywords["linenospecial"] = true - pygmentsKeywords["nobackground"] = true - pygmentsKeywords["lineseparator"] = true - pygmentsKeywords["lineanchors"] = true - pygmentsKeywords["linespans"] = true - pygmentsKeywords["anchorlinenos"] = true - pygmentsKeywords["startinline"] = true -} - -func parseOptions(defaults map[string]string, in string) (map[string]string, error) { - in = strings.Trim(in, " ") - opts := make(map[string]string) - - for k, v := range defaults { - opts[k] = v - } - - if in == "" { - return opts, nil - } - - for _, v := range strings.Split(in, ",") { - keyVal := strings.Split(v, "=") - key := strings.ToLower(strings.Trim(keyVal[0], " ")) - if len(keyVal) != 2 || !pygmentsKeywords[key] { - return opts, fmt.Errorf("invalid Pygments option: %s", key) - } - opts[key] = keyVal[1] - } - - return opts, nil -} - -func createOptionsString(options map[string]string) string { - var keys []string - for k := range options { - keys = append(keys, k) - } - sort.Strings(keys) - - var optionsStr string - for i, k := range keys { - optionsStr += fmt.Sprintf("%s=%s", k, options[k]) - if i < len(options)-1 { - optionsStr += "," - } - } - - return optionsStr -} - -func parseDefaultPygmentsOpts(cfg config.Provider) (map[string]string, error) { - options, err := parseOptions(nil, cfg.GetString("pygmentsOptions")) - if err != nil { - return nil, err - } - - if cfg.IsSet("pygmentsStyle") { - options["style"] = cfg.GetString("pygmentsStyle") - } - - if cfg.IsSet("pygmentsUseClasses") { - if cfg.GetBool("pygmentsUseClasses") { - options["noclasses"] = "false" - } else { - options["noclasses"] = "true" - } - - } - - if _, ok := options["encoding"]; !ok { - options["encoding"] = "utf8" - } - - return options, nil -} - -func (cs *ContentSpec) chromaFormatterFromOptions(pygmentsOpts map[string]string) (chroma.Formatter, error) { - var options = []html.Option{html.TabWidth(4)} - - if pygmentsOpts["noclasses"] == "false" { - options = append(options, html.WithClasses()) - } - - lineNumbers := pygmentsOpts["linenos"] - if lineNumbers != "" { - options = append(options, html.WithLineNumbers()) - if lineNumbers != "inline" { - options = append(options, html.LineNumbersInTable()) - } - } - - startLineStr := pygmentsOpts["linenostart"] - var startLine = 1 - if startLineStr != "" { - - line, err := strconv.Atoi(strings.TrimSpace(startLineStr)) - if err == nil { - startLine = line - options = append(options, html.BaseLineNumber(startLine)) - } - } - - hlLines := pygmentsOpts["hl_lines"] - - if hlLines != "" { - ranges, err := hlLinesToRanges(startLine, hlLines) - - if err == nil { - options = append(options, html.HighlightLines(ranges)) - } - } - - return html.New(options...), nil -} - -func (cs *ContentSpec) parsePygmentsOpts(in string) (map[string]string, error) { - opts, err := parseOptions(cs.defatultPygmentsOpts, in) - if err != nil { - return nil, err - } - return opts, nil - -} - -func (cs *ContentSpec) createPygmentsOptionsString(in string) (string, error) { - opts, err := cs.parsePygmentsOpts(in) - if err != nil { - return "", err - } - return createOptionsString(opts), nil -} - -// startLine compansates for https://github.com/alecthomas/chroma/issues/30 -func hlLinesToRanges(startLine int, s string) ([][2]int, error) { - var ranges [][2]int - s = strings.TrimSpace(s) - - if s == "" { - return ranges, nil - } - - // Variants: - // 1 2 3 4 - // 1-2 3-4 - // 1-2 3 - // 1 3-4 - // 1 3-4 - fields := strings.Split(s, " ") - for _, field := range fields { - field = strings.TrimSpace(field) - if field == "" { - continue - } - numbers := strings.Split(field, "-") - var r [2]int - first, err := strconv.Atoi(numbers[0]) - if err != nil { - return ranges, err - } - first = first + startLine - 1 - r[0] = first - if len(numbers) > 1 { - second, err := strconv.Atoi(numbers[1]) - if err != nil { - return ranges, err - } - second = second + startLine - 1 - r[1] = second - } else { - r[1] = first - } - - ranges = append(ranges, r) - } - return ranges, nil - -} diff --git a/helpers/pygments_test.go b/helpers/pygments_test.go deleted file mode 100644 index 05d86e104..000000000 --- a/helpers/pygments_test.go +++ /dev/null @@ -1,300 +0,0 @@ -// Copyright 2015 The Hugo Authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package helpers - -import ( - "fmt" - "reflect" - "testing" - - "github.com/alecthomas/chroma/formatters/html" - - qt "github.com/frankban/quicktest" - "github.com/spf13/viper" -) - -func TestParsePygmentsArgs(t *testing.T) { - c := qt.New(t) - - for i, this := range []struct { - in string - pygmentsStyle string - pygmentsUseClasses bool - expect1 interface{} - }{ - {"", "foo", true, "encoding=utf8,noclasses=false,style=foo"}, - {"style=boo,noclasses=true", "foo", true, "encoding=utf8,noclasses=true,style=boo"}, - {"Style=boo, noClasses=true", "foo", true, "encoding=utf8,noclasses=true,style=boo"}, - {"noclasses=true", "foo", true, "encoding=utf8,noclasses=true,style=foo"}, - {"style=boo", "foo", true, "encoding=utf8,noclasses=false,style=boo"}, - {"boo=invalid", "foo", false, false}, - {"style", "foo", false, false}, - } { - - v := viper.New() - v.Set("pygmentsStyle", this.pygmentsStyle) - v.Set("pygmentsUseClasses", this.pygmentsUseClasses) - spec, err := NewContentSpec(v, nil, nil) - c.Assert(err, qt.IsNil) - - result1, err := spec.createPygmentsOptionsString(this.in) - if b, ok := this.expect1.(bool); ok && !b { - if err == nil { - t.Errorf("[%d] parsePygmentArgs didn't return an expected error", i) - } - } else { - if err != nil { - t.Errorf("[%d] parsePygmentArgs failed: %s", i, err) - continue - } - if result1 != this.expect1 { - t.Errorf("[%d] parsePygmentArgs got %v but expected %v", i, result1, this.expect1) - } - - } - } -} - -func TestParseDefaultPygmentsArgs(t *testing.T) { - c := qt.New(t) - - expect := "encoding=utf8,noclasses=false,style=foo" - - for i, this := range []struct { - in string - pygmentsStyle interface{} - pygmentsUseClasses interface{} - pygmentsOptions string - }{ - {"", "foo", true, "style=override,noclasses=override"}, - {"", nil, nil, "style=foo,noclasses=false"}, - {"style=foo,noclasses=false", nil, nil, "style=override,noclasses=override"}, - {"style=foo,noclasses=false", "override", false, "style=override,noclasses=override"}, - } { - v := viper.New() - - v.Set("pygmentsOptions", this.pygmentsOptions) - - if s, ok := this.pygmentsStyle.(string); ok { - v.Set("pygmentsStyle", s) - } - - if b, ok := this.pygmentsUseClasses.(bool); ok { - v.Set("pygmentsUseClasses", b) - } - - spec, err := NewContentSpec(v, nil, nil) - c.Assert(err, qt.IsNil) - - result, err := spec.createPygmentsOptionsString(this.in) - if err != nil { - t.Errorf("[%d] parsePygmentArgs failed: %s", i, err) - continue - } - if result != expect { - t.Errorf("[%d] parsePygmentArgs got %v but expected %v", i, result, expect) - } - } -} - -type chromaInfo struct { - classes bool - lineNumbers bool - lineNumbersInTable bool - highlightRangesLen int - highlightRangesStr string - baseLineNumber int -} - -func formatterChromaInfo(f *html.Formatter) chromaInfo { - v := reflect.ValueOf(f).Elem() - c := chromaInfo{} - // Hack: - - c.classes = f.Classes - c.lineNumbers = v.FieldByName("lineNumbers").Bool() - c.lineNumbersInTable = v.FieldByName("lineNumbersInTable").Bool() - c.baseLineNumber = int(v.FieldByName("baseLineNumber").Int()) - vv := v.FieldByName("highlightRanges") - c.highlightRangesLen = vv.Len() - c.highlightRangesStr = fmt.Sprint(vv) - - return c -} - -func TestChromaHTMLHighlight(t *testing.T) { - c := qt.New(t) - - v := viper.New() - v.Set("pygmentsUseClasses", true) - spec, err := NewContentSpec(v, nil, nil) - c.Assert(err, qt.IsNil) - - result, err := spec.Highlight(`echo "Hello"`, "bash", "") - c.Assert(err, qt.IsNil) - - c.Assert(result, qt.Contains, `
echo "Hello"
`) - -} - -func TestChromaHTMLFormatterFromOptions(t *testing.T) { - c := qt.New(t) - - for i, this := range []struct { - in string - pygmentsStyle interface{} - pygmentsUseClasses interface{} - pygmentsOptions string - assert func(c chromaInfo) - }{ - {"", "monokai", true, "style=manni,noclasses=true", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, true) - c.Assert(ci.lineNumbers, qt.Equals, false) - c.Assert(ci.highlightRangesLen, qt.Equals, 0) - - }}, - {"", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, true) - }}, - {"linenos=sure,hl_lines=1 2 3", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, true) - c.Assert(ci.lineNumbers, qt.Equals, true) - c.Assert(ci.highlightRangesLen, qt.Equals, 3) - c.Assert(ci.highlightRangesStr, qt.Equals, "[[1 1] [2 2] [3 3]]") - c.Assert(ci.baseLineNumber, qt.Equals, 1) - }}, - {"linenos=inline,hl_lines=1,linenostart=4", nil, nil, "style=monokai,noclasses=false", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, true) - c.Assert(ci.lineNumbers, qt.Equals, true) - c.Assert(ci.lineNumbersInTable, qt.Equals, false) - c.Assert(ci.highlightRangesLen, qt.Equals, 1) - // This compansates for https://github.com/alecthomas/chroma/issues/30 - c.Assert(ci.highlightRangesStr, qt.Equals, "[[4 4]]") - c.Assert(ci.baseLineNumber, qt.Equals, 4) - }}, - {"linenos=table", nil, nil, "style=monokai", func(ci chromaInfo) { - c.Assert(ci.lineNumbers, qt.Equals, true) - c.Assert(ci.lineNumbersInTable, qt.Equals, true) - }}, - {"style=monokai,noclasses=false", nil, nil, "style=manni,noclasses=true", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, true) - }}, - {"style=monokai,noclasses=true", "friendly", false, "style=manni,noclasses=false", func(ci chromaInfo) { - c.Assert(ci.classes, qt.Equals, false) - }}, - } { - v := viper.New() - - v.Set("pygmentsOptions", this.pygmentsOptions) - - if s, ok := this.pygmentsStyle.(string); ok { - v.Set("pygmentsStyle", s) - } - - if b, ok := this.pygmentsUseClasses.(bool); ok { - v.Set("pygmentsUseClasses", b) - } - - spec, err := NewContentSpec(v, nil, nil) - c.Assert(err, qt.IsNil) - - opts, err := spec.parsePygmentsOpts(this.in) - if err != nil { - t.Fatalf("[%d] parsePygmentsOpts failed: %s", i, err) - } - - chromaFormatter, err := spec.chromaFormatterFromOptions(opts) - if err != nil { - t.Fatalf("[%d] chromaFormatterFromOptions failed: %s", i, err) - } - - this.assert(formatterChromaInfo(chromaFormatter.(*html.Formatter))) - } -} - -func TestHlLinesToRanges(t *testing.T) { - var zero [][2]int - - for _, this := range []struct { - in string - startLine int - expected interface{} - }{ - {"", 1, zero}, - {"1 4", 1, [][2]int{{1, 1}, {4, 4}}}, - {"1 4", 2, [][2]int{{2, 2}, {5, 5}}}, - {"1-4 5-8", 1, [][2]int{{1, 4}, {5, 8}}}, - {" 1 4 ", 1, [][2]int{{1, 1}, {4, 4}}}, - {"1-4 5-8 ", 1, [][2]int{{1, 4}, {5, 8}}}, - {"1-4 5", 1, [][2]int{{1, 4}, {5, 5}}}, - {"4 5-9", 1, [][2]int{{4, 4}, {5, 9}}}, - {" 1 -4 5 - 8 ", 1, true}, - {"a b", 1, true}, - } { - got, err := hlLinesToRanges(this.startLine, this.in) - - if expectErr, ok := this.expected.(bool); ok && expectErr { - if err == nil { - t.Fatal("No error") - } - } else if err != nil { - t.Fatalf("Got error: %s", err) - } else if !reflect.DeepEqual(this.expected, got) { - t.Fatalf("Expected\n%v but got\n%v", this.expected, got) - } - } -} - -func BenchmarkChromaHighlight(b *testing.B) { - c := qt.New(b) - v := viper.New() - - v.Set("pygmentsstyle", "trac") - v.Set("pygmentsuseclasses", false) - v.Set("pygmentsuseclassic", false) - - code := `// GetTitleFunc returns a func that can be used to transform a string to -// title case. -// -// The supported styles are -// -// - "Go" (strings.Title) -// - "AP" (see https://www.apstylebook.com/) -// - "Chicago" (see http://www.chicagomanualofstyle.org/home.html) -// -// If an unknown or empty style is provided, AP style is what you get. -func GetTitleFunc(style string) func(s string) string { - switch strings.ToLower(style) { - case "go": - return strings.Title - case "chicago": - tc := transform.NewTitleConverter(transform.ChicagoStyle) - return tc.Title - default: - tc := transform.NewTitleConverter(transform.APStyle) - return tc.Title - } -} -` - - spec, err := NewContentSpec(v, nil, nil) - c.Assert(err, qt.IsNil) - - for i := 0; i < b.N; i++ { - _, err := spec.Highlight(code, "go", "linenos=inline,hl_lines=8 15-17") - if err != nil { - b.Fatal(err) - } - } -} diff --git a/hugolib/case_insensitive_test.go b/hugolib/case_insensitive_test.go index 9c2662044..4a6b8f3a0 100644 --- a/hugolib/case_insensitive_test.go +++ b/hugolib/case_insensitive_test.go @@ -208,7 +208,6 @@ Page2: {{ $page2.Params.ColoR }} "Partial Site Global: green|yellow", "Page Title: Side 1", "Site Title: Nynorsk title", - "«Hi»", // angled quotes "Page2: black ", ) diff --git a/hugolib/config.go b/hugolib/config.go index 8a9c42b3c..133d126d6 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -597,11 +597,6 @@ func loadDefaultSettingsFor(v *viper.Viper) error { v.SetDefault("taxonomies", map[string]string{"tag": "tags", "category": "categories"}) v.SetDefault("permalinks", make(map[string]string)) v.SetDefault("sitemap", config.Sitemap{Priority: -1, Filename: "sitemap.xml"}) - v.SetDefault("pygmentsStyle", "monokai") - v.SetDefault("pygmentsUseClasses", false) - v.SetDefault("pygmentsCodeFences", false) - v.SetDefault("pygmentsUseClassic", false) - v.SetDefault("pygmentsOptions", "") v.SetDefault("disableLiveReload", false) v.SetDefault("pluralizeListTitles", true) v.SetDefault("forceSyncStatic", false) diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go index 1a690cdd9..03853bff6 100644 --- a/hugolib/hugo_sites_build_test.go +++ b/hugolib/hugo_sites_build_test.go @@ -671,7 +671,7 @@ END b.CreateSites().Build(BuildCfg{}) - contentMatchers := []string{"

Another header

", "

Another header

", "

The End.

"} + contentMatchers := []string{"

Another header

", "

Another header

", "

The End.

"} for i := 1; i <= numPages; i++ { if i%3 != 0 { @@ -691,13 +691,13 @@ END checkContent(b, fmt.Sprintf("public/%s/page%d/index.json", section, i), contentMatchers...) } - checkContent(b, "public/s1/index.html", "P: s1/_index.md\nList: 10|List Content: 8335\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8335\n\nRender 1: View: 8335\n\nRender 2: View: 8335\n\nRender 3: View: 8335\n\nRender 4: View: 8335\n\nEND\n") - checkContent(b, "public/s2/index.html", "P: s2/_index.md\nList: 10|List Content: 8335", "Render 4: View: 8335\n\nEND") - checkContent(b, "public/index.html", "P: _index.md\nList: 10|List Content: 8335", "4: View: 8335\n\nEND") + checkContent(b, "public/s1/index.html", "P: s1/_index.md\nList: 10|List Content: 8033\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8033\n\nRender 1: View: 8033\n\nRender 2: View: 8033\n\nRender 3: View: 8033\n\nRender 4: View: 8033\n\nEND\n") + checkContent(b, "public/s2/index.html", "P: s2/_index.md\nList: 10|List Content: 8033", "Render 4: View: 8033\n\nEND") + checkContent(b, "public/index.html", "P: _index.md\nList: 10|List Content: 8033", "4: View: 8033\n\nEND") // Check paginated pages for i := 2; i <= 9; i++ { - checkContent(b, fmt.Sprintf("public/page/%d/index.html", i), fmt.Sprintf("Page: %d", i), "Content: 8335\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8335", "Render 4: View: 8335\n\nEND") + checkContent(b, fmt.Sprintf("public/page/%d/index.html", i), fmt.Sprintf("Page: %d", i), "Content: 8033\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8033", "Render 4: View: 8033\n\nEND") } } @@ -977,7 +977,10 @@ enableRobotsTXT = true [permalinks] other = "/somewhere/else/:filename" -[blackfriday] +# TODO(bep) +[markup] + defaultMarkdownHandler = "blackfriday" +[markup.blackfriday] angledQuotes = true [Taxonomies] @@ -1035,7 +1038,10 @@ enableRobotsTXT: true permalinks: other: "/somewhere/else/:filename" -blackfriday: +# TODO(bep) +markup: + defaultMarkdownHandler: blackfriday + blackFriday: angledQuotes: true Taxonomies: @@ -1093,9 +1099,12 @@ var multiSiteJSONConfigTemplate = ` "permalinks": { "other": "/somewhere/else/:filename" }, - "blackfriday": { - "angledQuotes": true - }, + "markup": { + "defaultMarkdownHandler": "blackfriday", + "blackfriday": { + "angledQuotes": true + } + }, "Taxonomies": { "tag": "tags" }, diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go index ca5c7007e..1fc69c218 100644 --- a/hugolib/page__meta.go +++ b/hugolib/page__meta.go @@ -565,7 +565,7 @@ func (pm *pageMeta) setMetadata(bucket *pagesMapBucket, p *pageState, frontmatte pm.sitemap = p.s.siteCfg.sitemap } - pm.markup = helpers.GuessType(pm.markup) + pm.markup = p.s.ContentSpec.ResolveMarkup(pm.markup) if draft != nil && published != nil { pm.draft = *draft @@ -596,7 +596,7 @@ func (p *pageMeta) applyDefaultValues() error { if p.markup == "" { if !p.File().IsZero() { // Fall back to file extension - p.markup = helpers.GuessType(p.File().Ext()) + p.markup = p.s.ContentSpec.ResolveMarkup(p.File().Ext()) } if p.markup == "" { p.markup = "markdown" @@ -638,14 +638,20 @@ func (p *pageMeta) applyDefaultValues() error { } } - if !p.f.IsZero() && p.markup != "html" { + if !p.f.IsZero() { var renderingConfigOverrides map[string]interface{} bfParam := getParamToLower(p, "blackfriday") if bfParam != nil { renderingConfigOverrides = maps.ToStringMap(bfParam) } - cp := p.s.ContentSpec.Converters.Get(p.markup) + markup := p.markup + if markup == "html" { + // Only used for shortcode inner content. + markup = "markdown" + } + + cp := p.s.ContentSpec.Converters.Get(markup) if cp == nil { return errors.Errorf("no content renderer found for markup %q", p.markup) } diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go index ef2419eca..59de10be3 100644 --- a/hugolib/page__per_output.go +++ b/hugolib/page__per_output.go @@ -77,7 +77,7 @@ func newPageContentOutput(p *pageState) func(f output.Format) (*pageContentOutpu // See https://github.com/gohugoio/hugo/issues/6210 if r := recover(); r != nil { err = fmt.Errorf("%s", r) - p.s.Log.ERROR.Println("[BUG] Got panic:\n", string(debug.Stack())) + p.s.Log.ERROR.Printf("[BUG] Got panic:\n%s\n%s", r, string(debug.Stack())) } }() @@ -103,11 +103,14 @@ func newPageContentOutput(p *pageState) func(f output.Format) (*pageContentOutpu if err != nil { return err } + cp.convertedResult = r cp.workContent = r.Bytes() - tmpContent, tmpTableOfContents := helpers.ExtractTOC(cp.workContent) - cp.tableOfContents = helpers.BytesToHTML(tmpTableOfContents) - cp.workContent = tmpContent + if _, ok := r.(converter.TableOfContentsProvider); !ok { + tmpContent, tmpTableOfContents := helpers.ExtractTOC(cp.workContent) + cp.tableOfContents = helpers.BytesToHTML(tmpTableOfContents) + cp.workContent = tmpContent + } } if cp.placeholdersEnabled { @@ -223,7 +226,8 @@ type pageContentOutput struct { // Content state - workContent []byte + workContent []byte + convertedResult converter.Result // Temporary storage of placeholders mapped to their content. // These are shortcodes etc. Some of these will need to be replaced @@ -284,6 +288,10 @@ func (p *pageContentOutput) Summary() template.HTML { func (p *pageContentOutput) TableOfContents() template.HTML { p.p.s.initInit(p.initMain, p.p) + if tocProvider, ok := p.convertedResult.(converter.TableOfContentsProvider); ok { + cfg := p.p.s.ContentSpec.Converters.GetMarkupConfig() + return template.HTML(tocProvider.TableOfContents().ToHTML(cfg.TableOfContents.StartLevel, cfg.TableOfContents.EndLevel)) + } return p.tableOfContents } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index abceec9c6..665827502 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -326,7 +326,7 @@ func normalizeContent(c string) string { func checkPageTOC(t *testing.T, page page.Page, toc string) { if page.TableOfContents() != template.HTML(toc) { - t.Fatalf("Page TableOfContents is: %q.\nExpected %q", page.TableOfContents(), toc) + t.Fatalf("Page TableOfContents is:\n%q.\nExpected %q", page.TableOfContents(), toc) } } @@ -442,6 +442,7 @@ func testAllMarkdownEnginesForPages(t *testing.T, func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithSummaryDelimiterAndMarkdownThatCrossesBorder) @@ -453,12 +454,12 @@ func TestPageWithDelimiterForMarkdownThatCrossesBorder(t *testing.T) { p := s.RegularPages()[0] if p.Summary() != template.HTML( - "

The best static site generator.1

") { + "

The best static site generator.1

") { t.Fatalf("Got summary:\n%q", p.Summary()) } cnt := content(p) - if cnt != "

The best static site generator.1

\n\n
\n\n
\n\n
    \n
  1. Many people say so.\n [return]
  2. \n
\n
" { + if cnt != "

The best static site generator.1

\n
\n
\n
    \n
  1. \n

    Many people say so.

    \n
  2. \n
\n
" { t.Fatalf("Got content:\n%q", cnt) } } @@ -673,23 +674,13 @@ func TestPageWithShortCodeInSummary(t *testing.T) { testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithShortcodeInSummary) } -func TestPageWithEmbeddedScriptTag(t *testing.T) { - t.Parallel() - assertFunc := func(t *testing.T, ext string, pages page.Pages) { - p := pages[0] - if ext == "ad" || ext == "rst" { - // TOD(bep) - return - } - checkPageContent(t, p, "\n", ext) - } - - testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithEmbeddedScript) -} - func TestPageWithAdditionalExtension(t *testing.T) { t.Parallel() cfg, fs := newTestCfg() + cfg.Set("markup", map[string]interface{}{ + "defaultMarkdownHandler": "blackfriday", // TODO(bep) + }) + c := qt.New(t) writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithAdditionalExtension) @@ -716,8 +707,8 @@ func TestTableOfContents(t *testing.T) { p := s.RegularPages()[0] - checkPageContent(t, p, "\n\n

For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.

\n\n

AA

\n\n

I have no idea, of course, how long it took me to reach the limit of the plain,\nbut at last I entered the foothills, following a pretty little canyon upward\ntoward the mountains. Beside me frolicked a laughing brooklet, hurrying upon\nits noisy way down to the silent sea. In its quieter pools I discovered many\nsmall fish, of four-or five-pound weight I should imagine. In appearance,\nexcept as to size and color, they were not unlike the whale of our own seas. As\nI watched them playing about I discovered, not only that they suckled their\nyoung, but that at intervals they rose to the surface to breathe as well as to\nfeed upon certain grasses and a strange, scarlet lichen which grew upon the\nrocks just above the water line.

\n\n

AAA

\n\n

I remember I felt an extraordinary persuasion that I was being played with,\nthat presently, when I was upon the very verge of safety, this mysterious\ndeath–as swift as the passage of light–would leap after me from the pit about\nthe cylinder and strike me down. ## BB

\n\n

BBB

\n\n

“You’re a great Granser,” he cried delightedly, “always making believe them little marks mean something.”

\n") - checkPageTOC(t, p, "") + checkPageContent(t, p, "

For some moments the old man did not reply. He stood with bowed head, buried in deep thought. But at last he spoke.

AA

I have no idea, of course, how long it took me to reach the limit of the plain, but at last I entered the foothills, following a pretty little canyon upward toward the mountains. Beside me frolicked a laughing brooklet, hurrying upon its noisy way down to the silent sea. In its quieter pools I discovered many small fish, of four-or five-pound weight I should imagine. In appearance, except as to size and color, they were not unlike the whale of our own seas. As I watched them playing about I discovered, not only that they suckled their young, but that at intervals they rose to the surface to breathe as well as to feed upon certain grasses and a strange, scarlet lichen which grew upon the rocks just above the water line.

AAA

I remember I felt an extraordinary persuasion that I was being played with, that presently, when I was upon the very verge of safety, this mysterious death–as swift as the passage of light–would leap after me from the pit about the cylinder and strike me down. ## BB

BBB

“You're a great Granser,” he cried delightedly, “always making believe them little marks mean something.”

") + checkPageTOC(t, p, "") } func TestPageWithMoreTag(t *testing.T) { @@ -1518,12 +1509,12 @@ Summary: In Chinese, 好 means good. b.AssertFileContent("public/p1/index.html", "WordCount: 510\nFuzzyWordCount: 600\nReadingTime: 3\nLen Plain: 2550\nLen PlainWords: 510\nTruncated: false\nLen Summary: 2549\nLen Content: 2557") - b.AssertFileContent("public/p2/index.html", "WordCount: 314\nFuzzyWordCount: 400\nReadingTime: 2\nLen Plain: 1569\nLen PlainWords: 314\nTruncated: true\nLen Summary: 25\nLen Content: 1583") + b.AssertFileContent("public/p2/index.html", "WordCount: 314\nFuzzyWordCount: 400\nReadingTime: 2\nLen Plain: 1569\nLen PlainWords: 314\nTruncated: true\nLen Summary: 25\nLen Content: 1582") - b.AssertFileContent("public/p3/index.html", "WordCount: 206\nFuzzyWordCount: 300\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 43\nLen Content: 652") - b.AssertFileContent("public/p4/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 43\nLen Content: 652") - b.AssertFileContent("public/p5/index.html", "WordCount: 206\nFuzzyWordCount: 300\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 229\nLen Content: 653") - b.AssertFileContent("public/p6/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: false\nLen Summary: 637\nLen Content: 653") + b.AssertFileContent("public/p3/index.html", "WordCount: 206\nFuzzyWordCount: 300\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 43\nLen Content: 651") + b.AssertFileContent("public/p4/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 43\nLen Content: 651") + b.AssertFileContent("public/p5/index.html", "WordCount: 206\nFuzzyWordCount: 300\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: true\nLen Summary: 229\nLen Content: 652") + b.AssertFileContent("public/p6/index.html", "WordCount: 7\nFuzzyWordCount: 100\nReadingTime: 1\nLen Plain: 638\nLen PlainWords: 7\nTruncated: false\nLen Summary: 637\nLen Content: 652") } @@ -1611,3 +1602,132 @@ author = "Jo Nesbø" "Author site config: Kurt Vonnegut") } + +func TestGoldmark(t *testing.T) { + t.Parallel() + + b := newTestSitesBuilder(t).WithConfigFile("toml", ` +baseURL = "https://example.org" + +[markup] +defaultMarkdownHandler="goldmark" +[markup.goldmark] +[markup.goldmark.renderer] +unsafe = false +[markup.highlight] +noClasses=false + + +`) + b.WithTemplatesAdded("_default/single.html", ` +Title: {{ .Title }} +ToC: {{ .TableOfContents }} +Content: {{ .Content }} + +`, "shortcodes/t.html", `T-SHORT`, "shortcodes/s.html", `## Code +{{ .Inner }} +`) + + content := ` ++++ +title = "A Page!" ++++ + +## Shortcode {{% t %}} in header + +## Code Fense in Shortcode + +{{% s %}} +$$$bash {hl_lines=[1]} +SHORT +$$$ +{{% /s %}} + +## Code Fence + +$$$bash {hl_lines=[1]} +MARKDOWN +$$$ + +` + content = strings.ReplaceAll(content, "$$$", "```") + + b.WithContent("page.md", content) + + b.Build(BuildCfg{}) + + b.AssertFileContent("public/page/index.html", + `