Skip to content

Commit

Permalink
Add Goldmark as the new default markdown handler
Browse files Browse the repository at this point in the history
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 gohugoio#5963
Fixes gohugoio#1778
  • Loading branch information
bep committed Nov 11, 2019
1 parent a2670bf commit f9bafca
Show file tree
Hide file tree
Showing 32 changed files with 1,632 additions and 204 deletions.
21 changes: 20 additions & 1 deletion docs/content/en/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ In addition to using a single site config file, one can use the `configDir` dire
- Each directory holds a group of files containing settings unique to an environment.
- Files can be localized to become language specific.


```
├── config
│ ├── _default
Expand Down Expand Up @@ -184,6 +183,9 @@ log (false)
logFile ("")
: Log File path (if set, logging enabled automatically).

markup
: See [Configure Markup](#configure-markup)

menu
: See [Add Non-content Entries to a Menu](/content-management/menus/#add-non-content-entries-to-a-menu).

Expand Down Expand Up @@ -303,6 +305,23 @@ enableemoji: true
```
{{% /note %}}

## Configure Markup

Below are all the default markup related configuration in Hugo. Note that you only need to add custom configuration if you want to change the defaults.

See the sections below for more information.

{{< code-toggle config="markup" />}}

### Configure Goldmark

{{< code-toggle config="markup.goldmark" />}}

### Configure Blackfriday

### Configure Highlight


## Configure Title Case

Set `titleCaseStyle` to specify the title style used by the [title](/functions/title/) template function and the automatic section titles in Hugo. It defaults to [AP Stylebook](https://www.apstylebook.com/) for title casing, but you can also set it to `Chicago` or `Go` (every word starts with a capital letter).
Expand Down
145 changes: 141 additions & 4 deletions docs/data/docs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"chroma": {
"lexers": [
{
"Name": "ABAP",
"Aliases": [
"ABAP",
"abap"
]
},
{
"Name": "ABNF",
"Aliases": [
Expand Down Expand Up @@ -134,6 +141,13 @@
"winbatch"
]
},
{
"Name": "BibTeX",
"Aliases": [
"bib",
"bibtex"
]
},
{
"Name": "BlitzBasic",
"Aliases": [
Expand Down Expand Up @@ -405,7 +419,8 @@
"Aliases": [
"forth",
"frt",
"fs"
"fs",
"fth"
]
},
{
Expand Down Expand Up @@ -579,12 +594,27 @@
"idris"
]
},
{
"Name": "Igor",
"Aliases": [
"igor",
"igorpro",
"ipf"
]
},
{
"Name": "Io",
"Aliases": [
"io"
]
},
{
"Name": "J",
"Aliases": [
"ijs",
"j"
]
},
{
"Name": "JSON",
"Aliases": [
Expand Down Expand Up @@ -1342,6 +1372,51 @@
}
]
},
"config": {
"markup": {
"defaultMarkdownHandler": "goldmark",
"tocStartLevel": 1,
"tocEndLevel": 3,
"highlight": {
"style": "monokai",
"codeFences": true,
"noClasses": false,
"lineNos": "",
"lineNoStart": 1,
"hl_Lines": ""
},
"goldmark": {
"typographer": true,
"footnote": true,
"definitionList": true,
"table": true,
"strikethrough": true,
"linkify": true,
"taskList": true,
"hardWraps": false,
"xHTML": false,
"unsafe": false
},
"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": [
{
Expand Down Expand Up @@ -1513,6 +1588,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"
]
}
]
},
Expand Down Expand Up @@ -2290,10 +2427,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"
Expand Down
34 changes: 34 additions & 0 deletions docs/layouts/shortcodes/code-toggle.html
Original file line number Diff line number Diff line change
@@ -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") }}
<div class="code relative" {{ with $file }}id="{{ . | urlize}}"{{ end }}>
<div class="code-nav flex flex-nowrap items-stretch">
{{- with $file -}}
<div class="san-serif f6 dib lh-solid pl2 pv2 mr2">{{ . }}.</div>
{{- end -}}
{{ range $langs }}
<button data-toggle-tab="{{ . }}" class="tab-button {{ cond (eq . "yaml") "active" ""}} ba san-serif f6 dib lh-solid ph2 pv2">{{ . }}</button>&nbsp;
{{ end }}
</div>
<div class="tab-content">
{{ range $langs }}
<div data-pane="{{ . }}" class="code-copy-content nt3 tab-pane {{ cond (eq . "yaml") "active" ""}}">
{{ highlight ($code | transform.Remarshal . | safeHTML) . ""}}
</div>
{{ if ne ($.Get "copy") "false" }}
<button class="needs-js copy copy-toggle bg-accent-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2" title="Copy this code to your clipboard." data-clipboard-action="copy" aria-label="copy button">
</button>
{{/* 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 }}
</div>

</div>
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ 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.2
github.com/yuin/goldmark-highlighting v0.0.0-20190830074347-93c30623ac23
go.opencensus.io v0.22.0 // indirect
gocloud.dev v0.15.0
golang.org/x/image v0.0.0-20190523035834-f03afa92d3ff
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ 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.3/go.mod h1:quT2EpvJNqkuPi6DmBHB+E33FXBgBBPzyH5++Dn1LPc=
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/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.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU=
github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae h1:C4Q9m+oXOxcSWwYk9XzzafY2xAVAaeubZbUHJkw3PlY=
github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
Expand Down Expand Up @@ -116,8 +118,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=
Expand Down Expand Up @@ -349,6 +349,11 @@ 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.0/go.mod h1:hDgn8A2EV4OniExoeJs1fSrmEc/T7w8+Teyq8YkThxQ=
github.com/yuin/goldmark v1.1.2 h1:grIesFXV7jYjICFHQUdmU1uRxwCoOagz1ciWfB3mK88=
github.com/yuin/goldmark v1.1.2/go.mod h1:hDgn8A2EV4OniExoeJs1fSrmEc/T7w8+Teyq8YkThxQ=
github.com/yuin/goldmark-highlighting v0.0.0-20190830074347-93c30623ac23 h1:byGBknnKoxM5UWREM+u1fXwJE3lCuBsvRuDNw7HF0FM=
github.com/yuin/goldmark-highlighting v0.0.0-20190830074347-93c30623ac23/go.mod h1:3FYTzt9w4R8wIZ1KUvvoCyOMYNcYzqLr6amkECg35Hc=
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=
Expand Down
5 changes: 0 additions & 5 deletions hugolib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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)
Expand Down Expand Up @@ -223,7 +224,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
Expand Down Expand Up @@ -284,6 +286,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.TocStartLevel, cfg.TocEndLevel))
}
return p.tableOfContents
}

Expand Down
Loading

0 comments on commit f9bafca

Please sign in to comment.