summaryrefslogtreecommitdiffstats
path: root/markup/goldmark/convert.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-04 11:28:19 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-01-04 19:46:01 +0100
commita82d2700fcc772aada15d65b8f76913ca23f7404 (patch)
treefa1c09eb1523d7cda303982b5c08661af9a194d6 /markup/goldmark/convert.go
parentae816452b171b6b6aabca6a7423ed28a653baaa2 (diff)
markup/goldmark: Make auto IDs GitHub compatible
You can turn off this behaviour: ```toml [markup] [markup.goldmark] [markup.goldmark.parser] autoHeadingIDAsciiOnly = true ``` Note that the `anchorize` now adapts its behaviour depending on the default Markdown handler. Fixes #6616
Diffstat (limited to 'markup/goldmark/convert.go')
-rw-r--r--markup/goldmark/convert.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go
index af204125f..7d50839e2 100644
--- a/markup/goldmark/convert.go
+++ b/markup/goldmark/convert.go
@@ -50,19 +50,33 @@ type provide struct {
func (p provide) New(cfg converter.ProviderConfig) (converter.Provider, error) {
md := newMarkdown(cfg)
+
return converter.NewProvider("goldmark", func(ctx converter.DocumentContext) (converter.Converter, error) {
return &goldmarkConverter{
ctx: ctx,
cfg: cfg,
md: md,
+ sanitizeAnchorName: func(s string) string {
+ return sanitizeAnchorNameString(s, cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDAsciiOnly)
+ },
}, nil
}), nil
}
+var (
+ _ converter.AnchorNameSanitizer = (*goldmarkConverter)(nil)
+)
+
type goldmarkConverter struct {
md goldmark.Markdown
ctx converter.DocumentContext
cfg converter.ProviderConfig
+
+ sanitizeAnchorName func(s string) string
+}
+
+func (c *goldmarkConverter) SanitizeAnchorName(s string) string {
+ return c.sanitizeAnchorName(s)
}
func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
@@ -226,7 +240,7 @@ func (c *goldmarkConverter) Convert(ctx converter.RenderContext) (result convert
buf := &bufWriter{Buffer: &bytes.Buffer{}}
result = buf
- pctx := newParserContext(ctx)
+ pctx := c.newParserContext(ctx)
reader := text.NewReader(ctx.Src)
doc := c.md.Parser().Parse(
@@ -265,8 +279,8 @@ func (c *goldmarkConverter) Supports(feature identity.Identity) bool {
return featureSet[feature.GetIdentity()]
}
-func newParserContext(rctx converter.RenderContext) *parserContext {
- ctx := parser.NewContext()
+func (c *goldmarkConverter) newParserContext(rctx converter.RenderContext) *parserContext {
+ ctx := parser.NewContext(parser.WithIDs(newIDFactory(c.cfg.MarkupConfig.Goldmark.Parser.AutoHeadingIDAsciiOnly)))
ctx.Set(tocEnableKey, rctx.RenderTOC)
return &parserContext{
Context: ctx,