diff --git a/docs/data/docs.yaml b/docs/data/docs.yaml index dcc96c590..036c21285 100644 --- a/docs/data/docs.yaml +++ b/docs/data/docs.yaml @@ -1065,6 +1065,15 @@ config: enable: false escapedSpace: false definitionList: true + extras: + insert: + enable: false + mark: + enable: false + subscript: + enable: false + superscript: + enable: false footnote: true linkify: true linkifyProtocol: https diff --git a/go.mod b/go.mod index 6a3a0c7fa..095e631e9 100644 --- a/go.mod +++ b/go.mod @@ -117,6 +117,7 @@ require ( github.com/dlclark/regexp2 v1.11.0 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/swag v0.22.8 // indirect + github.com/gohugoio/hugo-goldmark-extensions/extras v0.0.0-20240503234250-234f8faa6be2 // indirect github.com/golang-jwt/jwt/v5 v5.1.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect diff --git a/go.sum b/go.sum index ead5b117f..dd79e6691 100644 --- a/go.sum +++ b/go.sum @@ -211,6 +211,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/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/hugo-goldmark-extensions/extras v0.0.0-20240503234250-234f8faa6be2 h1:dDKUJ3mWRcrH16pRBjfcE2rjgjCe2ukn2RM0e5BP76Q= +github.com/gohugoio/hugo-goldmark-extensions/extras v0.0.0-20240503234250-234f8faa6be2/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/go.mod h1:g9CCh+Ci2IMbPUrVJuXbBTrA+rIIx5+hDQ4EXYaQDoM= github.com/gohugoio/locales v0.14.0 h1:Q0gpsZwfv7ATHMbcTNepFd59H7GoykzWJIxi113XGDc= diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go index d7180140d..b26c1c034 100644 --- a/markup/goldmark/convert.go +++ b/markup/goldmark/convert.go @@ -17,6 +17,8 @@ package goldmark import ( "bytes" + "github.com/gohugoio/hugo-goldmark-extensions/extras" + xast "github.com/gohugoio/hugo-goldmark-extensions/extras/ast" "github.com/gohugoio/hugo-goldmark-extensions/passthrough" "github.com/gohugoio/hugo/markup/goldmark/hugocontext" "github.com/yuin/goldmark/util" @@ -194,6 +196,22 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown { )) } + if cfg.Extensions.Extras.Insert.Enable { + extensions = append(extensions, extras.New(extras.Config{InlineTagType: xast.Insert})) + } + + if cfg.Extensions.Extras.Mark.Enable { + extensions = append(extensions, extras.New(extras.Config{InlineTagType: xast.Mark})) + } + + if cfg.Extensions.Extras.Subscript.Enable { + extensions = append(extensions, extras.New(extras.Config{InlineTagType: xast.Subscript})) + } + + if cfg.Extensions.Extras.Superscript.Enable { + extensions = append(extensions, extras.New(extras.Config{InlineTagType: xast.Superscript})) + } + if pcfg.Conf.EnableEmoji() { extensions = append(extensions, emoji.Emoji) } diff --git a/markup/goldmark/goldmark_config/config.go b/markup/goldmark/goldmark_config/config.go index c22852b29..620475c48 100644 --- a/markup/goldmark/goldmark_config/config.go +++ b/markup/goldmark/goldmark_config/config.go @@ -49,6 +49,20 @@ var Default = Config{ EastAsianLineBreaksStyle: "simple", EscapedSpace: false, }, + Extras: Extras{ + Superscript: Superscript{ + Enable: false, + }, + Subscript: Subscript{ + Enable: false, + }, + Insert: Insert{ + Enable: false, + }, + Mark: Mark{ + Enable: false, + }, + }, Passthrough: Passthrough{ Enable: false, Delimiters: DelimitersConfig{ @@ -112,6 +126,7 @@ type Extensions struct { Typographer Typographer Footnote bool DefinitionList bool + Extras Extras Passthrough Passthrough // GitHub flavored markdown @@ -150,7 +165,32 @@ type Typographer struct { 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 type Passthrough struct { // Whether to enable the extension diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go index ffeb763a7..82b41cc67 100644 --- a/markup/goldmark/goldmark_integration_test.go +++ b/markup/goldmark/goldmark_integration_test.go @@ -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", + "

++insert++

", + "

==mark==

", + "

H~2~0

", + "

1^st^

", + ) + + files = strings.ReplaceAll(files, "enable = false", "enable = true") + + b = hugolib.Test(t, files) + + b.AssertFileContent("public/index.html", + "

insert

", + "

mark

", + "

H20

", + "

1st

", + ) +}