diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-12-03 12:33:48 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-12-05 15:00:47 +0100 |
commit | 63126c6359a693345a3a81b22e0f95660b248044 (patch) | |
tree | 7f2fdf6af58735564cf3be57efbdad594150fa05 /markup/goldmark/convert.go | |
parent | 535ea8cc9bf20b1ba6f656f9f3eee3818c6dc537 (diff) | |
download | hugo-63126c6359a693345a3a81b22e0f95660b248044.tar.gz hugo-63126c6359a693345a3a81b22e0f95660b248044.zip |
markup/goldmark: Add removeSurroundingParagraph for Markdown images
* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node
* Adds IsBlock and Ordinal (zero based) field to the image context passed to the image render hooks
IsBlock is set to true if `wrapStandAloneImageWithinParagraph = false` and the image's parent node has only one child.
Closes #8362
Fixes #10492
Fixes #10494
Fixes #10501
Diffstat (limited to 'markup/goldmark/convert.go')
-rw-r--r-- | markup/goldmark/convert.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go index ba85831b0..a179cd233 100644 --- a/markup/goldmark/convert.go +++ b/markup/goldmark/convert.go @@ -17,12 +17,12 @@ package goldmark import ( "bytes" + "github.com/gohugoio/hugo/identity" "github.com/gohugoio/hugo/markup/goldmark/codeblocks" + "github.com/gohugoio/hugo/markup/goldmark/images" "github.com/gohugoio/hugo/markup/goldmark/internal/extensions/attributes" "github.com/gohugoio/hugo/markup/goldmark/internal/render" - "github.com/gohugoio/hugo/identity" - "github.com/gohugoio/hugo/markup/converter" "github.com/gohugoio/hugo/markup/tableofcontents" "github.com/yuin/goldmark" @@ -33,6 +33,10 @@ import ( "github.com/yuin/goldmark/text" ) +const ( + internalAttrPrefix = "_h__" +) + // Provider is the package entry point. var Provider converter.ProviderProvider = provide{} @@ -92,6 +96,8 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown { parserOptions []parser.Option ) + extensions = append(extensions, images.New(cfg.Parser.WrapStandAloneImageWithinParagraph)) + if mcfg.Highlight.CodeFences { extensions = append(extensions, codeblocks.New()) } @@ -131,7 +137,6 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown { if cfg.Parser.Attribute.Title { parserOptions = append(parserOptions, parser.WithAttribute()) } - if cfg.Parser.Attribute.Block { extensions = append(extensions, attributes.New()) } |