markup/goldmark: Fix handling of legacy attribute config

See #7548
This commit is contained in:
Bjørn Erik Pedersen 2021-02-09 09:23:18 +01:00
parent 2681633db8
commit e6dd312812
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -14,6 +14,7 @@
package markup_config package markup_config
import ( import (
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config" "github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
@ -23,6 +24,7 @@ import (
"github.com/gohugoio/hugo/markup/tableofcontents" "github.com/gohugoio/hugo/markup/tableofcontents"
"github.com/gohugoio/hugo/parser" "github.com/gohugoio/hugo/parser"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/spf13/cast"
) )
type Config struct { type Config struct {
@ -44,12 +46,11 @@ type Config struct {
func Decode(cfg config.Provider) (conf Config, err error) { func Decode(cfg config.Provider) (conf Config, err error) {
conf = Default conf = Default
normalizeConfig(cfg)
m := cfg.GetStringMap("markup") m := cfg.GetStringMap("markup")
if m == nil { if m == nil {
return return
} }
normalizeConfig(m)
err = mapstructure.WeakDecode(m, &conf) err = mapstructure.WeakDecode(m, &conf)
if err != nil { if err != nil {
@ -67,14 +68,19 @@ func Decode(cfg config.Provider) (conf Config, err error) {
return return
} }
func normalizeConfig(cfg config.Provider) { func normalizeConfig(m map[string]interface{}) {
v, err := maps.GetNestedParam("goldmark.parser", ".", m)
if err != nil {
return
}
vm := cast.ToStringMap(v)
// Changed from a bool in 0.81.0 // Changed from a bool in 0.81.0
const attrKey = "markup.goldmark.parser.attribute" if vv, found := vm["attribute"]; found {
av := cfg.Get(attrKey) if vvb, ok := vv.(bool); ok {
if avb, ok := av.(bool); ok { vm["attribute"] = goldmark_config.ParserAttribute{
cfg.Set(attrKey, goldmark_config.ParserAttribute{ Title: vvb,
Title: avb, }
}) }
} }
} }