summaryrefslogtreecommitdiffstats
path: root/markup
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-05 11:29:22 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-05 11:29:22 +0100
commit8f071fc159ce9a0fc0ea14a73bde8f299bedd109 (patch)
treeaee22932ccdfd1e4ed82e7c242f7f65f17eaf701 /markup
parent469351d5b6a1521069c8d82539476714df16a094 (diff)
markup/goldmark: Make the autoID type config a string
To potentially make room for one more. See #6707
Diffstat (limited to 'markup')
-rw-r--r--markup/goldmark/autoid.go6
-rw-r--r--markup/goldmark/convert.go6
-rw-r--r--markup/goldmark/convert_test.go4
-rw-r--r--markup/goldmark/goldmark_config/config.go17
4 files changed, 22 insertions, 11 deletions
diff --git a/markup/goldmark/autoid.go b/markup/goldmark/autoid.go
index c064a76b3..aaf1852d1 100644
--- a/markup/goldmark/autoid.go
+++ b/markup/goldmark/autoid.go
@@ -19,6 +19,8 @@ import (
"unicode"
"unicode/utf8"
+ "github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
+
"github.com/gohugoio/hugo/common/text"
"github.com/yuin/goldmark/ast"
@@ -85,10 +87,10 @@ type idFactory struct {
vals map[string]struct{}
}
-func newIDFactory(asciiOnly bool) *idFactory {
+func newIDFactory(idType string) *idFactory {
return &idFactory{
vals: make(map[string]struct{}),
- asciiOnly: asciiOnly,
+ asciiOnly: idType == goldmark_config.AutoHeadingIDTypeGitHubAscii,
}
}
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go
index 7d50839e2..c6f958366 100644
--- a/markup/goldmark/convert.go
+++ b/markup/goldmark/convert.go
@@ -28,8 +28,8 @@ import (
"github.com/spf13/afero"
"github.com/gohugoio/hugo/hugofs"
-
"github.com/gohugoio/hugo/markup/converter"
+ "github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
"github.com/gohugoio/hugo/markup/highlight"
"github.com/gohugoio/hugo/markup/tableofcontents"
"github.com/yuin/goldmark"
@@ -57,7 +57,7 @@ func (p provide) New(cfg converter.ProviderConfig) (converter.Provider, error) {
cfg: cfg,
md: md,
sanitizeAnchorName: func(s string) string {
- return sanitizeAnchorNameString(s, cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDAsciiOnly)
+ return sanitizeAnchorNameString(s, cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDType == goldmark_config.AutoHeadingIDTypeGitHub)
},
}, nil
}), nil
@@ -280,7 +280,7 @@ func (c *goldmarkConverter) Supports(feature identity.Identity) bool {
}
func (c *goldmarkConverter) newParserContext(rctx converter.RenderContext) *parserContext {
- ctx := parser.NewContext(parser.WithIDs(newIDFactory(c.cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDAsciiOnly)))
+ ctx := parser.NewContext(parser.WithIDs(newIDFactory(c.cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDType)))
ctx.Set(tocEnableKey, rctx.RenderTOC)
return &parserContext{
Context: ctx,
diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go
index b9bf01ef5..3c173fb0a 100644
--- a/markup/goldmark/convert_test.go
+++ b/markup/goldmark/convert_test.go
@@ -17,6 +17,8 @@ import (
"strings"
"testing"
+ "github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
+
"github.com/gohugoio/hugo/markup/highlight"
"github.com/gohugoio/hugo/markup/markup_config"
@@ -169,7 +171,7 @@ func TestConvertAutoIDAsciiOnly(t *testing.T) {
## God is Good: 神真美好
`
mconf := markup_config.Default
- mconf.Goldmark.Parser.AutoHeadingIDAsciiOnly = true
+ mconf.Goldmark.Parser.AutoHeadingIDType = goldmark_config.AutoHeadingIDTypeGitHubAscii
b := convert(c, mconf, content)
got := string(b.Bytes())
diff --git a/markup/goldmark/goldmark_config/config.go b/markup/goldmark/goldmark_config/config.go
index 2454eb46f..47399b52c 100644
--- a/markup/goldmark/goldmark_config/config.go
+++ b/markup/goldmark/goldmark_config/config.go
@@ -14,6 +14,11 @@
// Package goldmark_config holds Goldmark related configuration.
package goldmark_config
+const (
+ AutoHeadingIDTypeGitHub = "github"
+ AutoHeadingIDTypeGitHubAscii = "github-ascii"
+)
+
// DefaultConfig holds the default Goldmark configuration.
var Default = Config{
Extensions: Extensions{
@@ -29,8 +34,9 @@ var Default = Config{
Unsafe: false,
},
Parser: Parser{
- AutoHeadingID: true,
- Attribute: true,
+ AutoHeadingID: true,
+ AutoHeadingIDType: AutoHeadingIDTypeGitHub,
+ Attribute: true,
},
}
@@ -69,9 +75,10 @@ type Parser struct {
// auto generated heading ids.
AutoHeadingID bool
- // When AutoHeadingID is enabled this will generate IDs with Ascii
- // characters only.
- AutoHeadingIDAsciiOnly bool
+ // The strategy to use when generating heading IDs.
+ // Available options are "github", "github-ascii".
+ // Default is "github", which will create GitHub-compatible anchor names.
+ AutoHeadingIDType string
// Enables custom attributes.
Attribute bool