mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
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
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user