diff --git a/markup/converter/hooks/hooks.go b/markup/converter/hooks/hooks.go
index a8666bdf0..a59da939e 100644
--- a/markup/converter/hooks/hooks.go
+++ b/markup/converter/hooks/hooks.go
@@ -37,6 +37,12 @@ type LinkContext interface {
PlainText() string
}
+type ImageLinkContext interface {
+ LinkContext
+ IsBlock() bool
+ Ordinal() int
+}
+
type CodeblockContext interface {
AttributesProvider
text.Positioner
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())
}
diff --git a/markup/goldmark/goldmark_config/config.go b/markup/goldmark/goldmark_config/config.go
index a3238091b..ff0b6bbef 100644
--- a/markup/goldmark/goldmark_config/config.go
+++ b/markup/goldmark/goldmark_config/config.go
@@ -36,8 +36,9 @@ var Default = Config{
Unsafe: false,
},
Parser: Parser{
- AutoHeadingID: true,
- AutoHeadingIDType: AutoHeadingIDTypeGitHub,
+ AutoHeadingID: true,
+ AutoHeadingIDType: AutoHeadingIDTypeGitHub,
+ WrapStandAloneImageWithinParagraph: true,
Attribute: ParserAttribute{
Title: true,
Block: false,
@@ -88,6 +89,9 @@ type Parser struct {
// Enables custom attributes.
Attribute ParserAttribute
+
+ // Whether to wrap stand-alone images within a paragraph or not.
+ WrapStandAloneImageWithinParagraph bool
}
type ParserAttribute struct {
diff --git a/markup/goldmark/images/integration_test.go b/markup/goldmark/images/integration_test.go
new file mode 100644
index 000000000..e8d1b880e
--- /dev/null
+++ b/markup/goldmark/images/integration_test.go
@@ -0,0 +1,113 @@
+package images_test
+
+import (
+ "strings"
+ "testing"
+
+ "github.com/gohugoio/hugo/hugolib"
+)
+
+func TestDisableWrapStandAloneImageWithinParagraph(t *testing.T) {
+ t.Parallel()
+
+ filesTemplate := `
+-- config.toml --
+[markup.goldmark.renderer]
+ unsafe = false
+[markup.goldmark.parser]
+wrapStandAloneImageWithinParagraph = CONFIG_VALUE
+[markup.goldmark.parser.attribute]
+ block = true
+ title = true
+-- content/p1.md --
+---
+title: "p1"
+---
+
+This is an inline image: ![Inline Image](/inline.jpg). Some more text.
+
+![Block Image](/block.jpg)
+{.b}
+
+
+-- layouts/_default/single.html --
+{{ .Content }}
+`
+
+ t.Run("With Hook, no wrap", func(t *testing.T) {
+ files := strings.ReplaceAll(filesTemplate, "CONFIG_VALUE", "false")
+ files = files + `-- layouts/_default/_markup/render-image.html --
+{{ if .IsBlock }}
+
+{{ else }}
+
+{{ end }}
+`
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ NeedsOsFS: false,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/p1/index.html",
+ "This is an inline image: \n\t\n. Some more text.
",
+ "