mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
markup/goldmark: Support extras extension
Enables inclusion of these HTML elements in Markdown: - Inserted Text (++inserted++) - Mark Text (==marked==) - Subscript (H~2~O) - Superscript (1^st^)
This commit is contained in:
parent
b1bf0bff2c
commit
ca9a77ef92
6 changed files with 113 additions and 1 deletions
|
@ -1065,6 +1065,15 @@ config:
|
||||||
enable: false
|
enable: false
|
||||||
escapedSpace: false
|
escapedSpace: false
|
||||||
definitionList: true
|
definitionList: true
|
||||||
|
extras:
|
||||||
|
insert:
|
||||||
|
enable: false
|
||||||
|
mark:
|
||||||
|
enable: false
|
||||||
|
subscript:
|
||||||
|
enable: false
|
||||||
|
superscript:
|
||||||
|
enable: false
|
||||||
footnote: true
|
footnote: true
|
||||||
linkify: true
|
linkify: true
|
||||||
linkifyProtocol: https
|
linkifyProtocol: https
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -35,6 +35,7 @@ require (
|
||||||
github.com/gobuffalo/flect v1.0.2
|
github.com/gobuffalo/flect v1.0.2
|
||||||
github.com/gobwas/glob v0.2.3
|
github.com/gobwas/glob v0.2.3
|
||||||
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e
|
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e
|
||||||
|
github.com/gohugoio/hugo-goldmark-extensions/extras v0.1.0
|
||||||
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0
|
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0
|
||||||
github.com/gohugoio/locales v0.14.0
|
github.com/gohugoio/locales v0.14.0
|
||||||
github.com/gohugoio/localescompressed v1.0.1
|
github.com/gohugoio/localescompressed v1.0.1
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -213,6 +213,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
|
||||||
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
|
||||||
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e h1:QArsSubW7eDh8APMXkByjQWvuljwPGAGQpJEFn0F0wY=
|
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e h1:QArsSubW7eDh8APMXkByjQWvuljwPGAGQpJEFn0F0wY=
|
||||||
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e/go.mod h1:3Ltoo9Banwq0gOtcOwxuHG6omk+AwsQPADyw2vQYOJQ=
|
github.com/gohugoio/go-i18n/v2 v2.1.3-0.20230805085216-e63c13218d0e/go.mod h1:3Ltoo9Banwq0gOtcOwxuHG6omk+AwsQPADyw2vQYOJQ=
|
||||||
|
github.com/gohugoio/hugo-goldmark-extensions/extras v0.1.0 h1:YhxZNU8y2vxV6Ibr7QJzzUlpr8oHHWX/l+Q1R/a5Zao=
|
||||||
|
github.com/gohugoio/hugo-goldmark-extensions/extras v0.1.0/go.mod h1:0cuvOnGKW7WeXA3i7qK6IS07FH1bgJ2XzOjQ7BMJYH4=
|
||||||
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0 h1:PCtO5l++psZf48yen2LxQ3JiOXxaRC6v0594NeHvGZg=
|
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0 h1:PCtO5l++psZf48yen2LxQ3JiOXxaRC6v0594NeHvGZg=
|
||||||
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0/go.mod h1:g9CCh+Ci2IMbPUrVJuXbBTrA+rIIx5+hDQ4EXYaQDoM=
|
github.com/gohugoio/hugo-goldmark-extensions/passthrough v0.2.0/go.mod h1:g9CCh+Ci2IMbPUrVJuXbBTrA+rIIx5+hDQ4EXYaQDoM=
|
||||||
github.com/gohugoio/locales v0.14.0 h1:Q0gpsZwfv7ATHMbcTNepFd59H7GoykzWJIxi113XGDc=
|
github.com/gohugoio/locales v0.14.0 h1:Q0gpsZwfv7ATHMbcTNepFd59H7GoykzWJIxi113XGDc=
|
||||||
|
|
|
@ -17,6 +17,7 @@ package goldmark
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
|
"github.com/gohugoio/hugo-goldmark-extensions/extras"
|
||||||
"github.com/gohugoio/hugo-goldmark-extensions/passthrough"
|
"github.com/gohugoio/hugo-goldmark-extensions/passthrough"
|
||||||
"github.com/gohugoio/hugo/markup/goldmark/hugocontext"
|
"github.com/gohugoio/hugo/markup/goldmark/hugocontext"
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
|
@ -113,6 +114,15 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
|
||||||
|
|
||||||
extensions = append(extensions, images.New(cfg.Parser.WrapStandAloneImageWithinParagraph))
|
extensions = append(extensions, images.New(cfg.Parser.WrapStandAloneImageWithinParagraph))
|
||||||
|
|
||||||
|
extensions = append(extensions, extras.New(
|
||||||
|
extras.Config{
|
||||||
|
Insert: extras.InsertConfig{Enable: cfg.Extensions.Extras.Insert.Enable},
|
||||||
|
Mark: extras.MarkConfig{Enable: cfg.Extensions.Extras.Mark.Enable},
|
||||||
|
Subscript: extras.SubscriptConfig{Enable: cfg.Extensions.Extras.Subscript.Enable},
|
||||||
|
Superscript: extras.SuperscriptConfig{Enable: cfg.Extensions.Extras.Superscript.Enable},
|
||||||
|
},
|
||||||
|
))
|
||||||
|
|
||||||
if mcfg.Highlight.CodeFences {
|
if mcfg.Highlight.CodeFences {
|
||||||
extensions = append(extensions, codeblocks.New())
|
extensions = append(extensions, codeblocks.New())
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,20 @@ var Default = Config{
|
||||||
EastAsianLineBreaksStyle: "simple",
|
EastAsianLineBreaksStyle: "simple",
|
||||||
EscapedSpace: false,
|
EscapedSpace: false,
|
||||||
},
|
},
|
||||||
|
Extras: Extras{
|
||||||
|
Superscript: Superscript{
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
Subscript: Subscript{
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
Insert: Insert{
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
Mark: Mark{
|
||||||
|
Enable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
Passthrough: Passthrough{
|
Passthrough: Passthrough{
|
||||||
Enable: false,
|
Enable: false,
|
||||||
Delimiters: DelimitersConfig{
|
Delimiters: DelimitersConfig{
|
||||||
|
@ -112,6 +126,7 @@ type Extensions struct {
|
||||||
Typographer Typographer
|
Typographer Typographer
|
||||||
Footnote bool
|
Footnote bool
|
||||||
DefinitionList bool
|
DefinitionList bool
|
||||||
|
Extras Extras
|
||||||
Passthrough Passthrough
|
Passthrough Passthrough
|
||||||
|
|
||||||
// GitHub flavored markdown
|
// GitHub flavored markdown
|
||||||
|
@ -150,7 +165,32 @@ type Typographer struct {
|
||||||
Apostrophe string
|
Apostrophe string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passthrough hold passthrough configuration.
|
// Extras holds extras configuration.
|
||||||
|
// github.com/hugoio/hugo-goldmark-extensions/extras
|
||||||
|
type Extras struct {
|
||||||
|
Insert Insert
|
||||||
|
Mark Mark
|
||||||
|
Subscript Subscript
|
||||||
|
Superscript Superscript
|
||||||
|
}
|
||||||
|
|
||||||
|
type Insert struct {
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mark struct {
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Subscript struct {
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Superscript struct {
|
||||||
|
Enable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Passthrough holds passthrough configuration.
|
||||||
// github.com/hugoio/hugo-goldmark-extensions/passthrough
|
// github.com/hugoio/hugo-goldmark-extensions/passthrough
|
||||||
type Passthrough struct {
|
type Passthrough struct {
|
||||||
// Whether to enable the extension
|
// Whether to enable the extension
|
||||||
|
|
|
@ -744,3 +744,53 @@ a^*=x-b^*
|
||||||
%!%
|
%!%
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExtrasExtension(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||||
|
[markup.goldmark.extensions.extras.insert]
|
||||||
|
enable = false
|
||||||
|
[markup.goldmark.extensions.extras.mark]
|
||||||
|
enable = false
|
||||||
|
[markup.goldmark.extensions.extras.subscript]
|
||||||
|
enable = false
|
||||||
|
[markup.goldmark.extensions.extras.superscript]
|
||||||
|
enable = false
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{ .Content }}
|
||||||
|
-- content/_index.md --
|
||||||
|
---
|
||||||
|
title: home
|
||||||
|
---
|
||||||
|
++insert++
|
||||||
|
|
||||||
|
==mark==
|
||||||
|
|
||||||
|
H~2~0
|
||||||
|
|
||||||
|
1^st^
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html",
|
||||||
|
"<p>++insert++</p>",
|
||||||
|
"<p>==mark==</p>",
|
||||||
|
"<p>H~2~0</p>",
|
||||||
|
"<p>1^st^</p>",
|
||||||
|
)
|
||||||
|
|
||||||
|
files = strings.ReplaceAll(files, "enable = false", "enable = true")
|
||||||
|
|
||||||
|
b = hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html",
|
||||||
|
"<p><ins>insert</ins></p>",
|
||||||
|
"<p><mark>mark</mark></p>",
|
||||||
|
"<p>H<sub>2</sub>0</p>",
|
||||||
|
"<p>1<sup>st</sup></p>",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue