markup/goldmark: Support passthrough extension

Fixes #10894
This commit is contained in:
Jeremy Kun
2024-01-06 08:53:24 -08:00
committed by Bjørn Erik Pedersen
parent 2dd608378d
commit d0d2c6795e
5 changed files with 161 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import (
"github.com/gohugoio/hugo/identity"
"github.com/gohugoio/hugo-goldmark-extensions/passthrough"
"github.com/gohugoio/hugo/markup/goldmark/codeblocks"
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
"github.com/gohugoio/hugo/markup/goldmark/images"
@@ -154,6 +155,33 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
extensions = append(extensions, c)
}
if cfg.Extensions.Passthrough.Enable {
configuredInlines := cfg.Extensions.Passthrough.Delimiters.Inline
configuredBlocks := cfg.Extensions.Passthrough.Delimiters.Block
inlineDelimiters := make([]passthrough.Delimiters, len(configuredInlines))
blockDelimiters := make([]passthrough.Delimiters, len(configuredBlocks))
for i, d := range configuredInlines {
inlineDelimiters[i] = passthrough.Delimiters{
Open: d[0],
Close: d[1],
}
}
for i, d := range configuredBlocks {
blockDelimiters[i] = passthrough.Delimiters{
Open: d[0],
Close: d[1],
}
}
extensions = append(extensions, passthrough.NewPassthroughWithDelimiters(
inlineDelimiters,
blockDelimiters,
))
}
if pcfg.Conf.EnableEmoji() {
extensions = append(extensions, emoji.Emoji)
}