diff options
Diffstat (limited to 'markup/goldmark/convert.go')
-rw-r--r-- | markup/goldmark/convert.go | 20 |
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, |