func TestRenderLinkWithMarkupInText(t *testing.T) {
b := newTestSitesBuilder(t)
+ b.WithConfigFile("toml", `
+
+baseURL="https://example.org"
+
+[markup]
+ [markup.goldmark]
+ [markup.goldmark.renderer]
+ unsafe = true
+
+`)
b.WithTemplates("index.html", `
{{ $p := site.GetPage "p1.md" }}
`,
"_default/_markup/render-link.html", `html-link: {{ .Destination | safeURL }}|Text: {{ .Text | safeHTML }}|Plain: {{ .PlainText | safeHTML }}`,
+ "_default/_markup/render-image.html", `html-image: {{ .Destination | safeURL }}|Text: {{ .Text | safeHTML }}|Plain: {{ .PlainText | safeHTML }}`,
)
b.WithContent("p1.md", `---
START: [**should be bold**](https://gohugo.io)END
Some regular **markup**.
+
+Image:
+
+END
+
`)
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
P1: <p>START: html-link: https://gohugo.io|Text: <strong>should be bold</strong>|Plain: should be boldEND</p>
<p>Some regular <strong>markup</strong>.</p>
+<p>html-image: image.jpg|Text: Hello<br> Goodbye|Plain: Hello GoodbyeEND</p>
`)
}
RSTART:{{ "**Bold Block Markdown**" | $p.RenderString $optBlock }}:REND
RSTART:{{ "/italic org mode/" | $p.RenderString $optOrg }}:REND
+
`)
b.WithContent("p1.md", `---
n := node.(*ast.Image)
var h *hooks.Render
- ctx, ok := w.(renderContextData)
+ ctx, ok := w.(*renderContext)
if ok {
h = ctx.RenderContext().RenderHooks
ok = h != nil && h.ImageRenderer != nil
return r.renderDefaultImage(w, source, node, entering)
}
- if !entering {
+ if entering {
+ // Store the current pos so we can capture the rendered text.
+ ctx.pos = ctx.Buffer.Len()
return ast.WalkContinue, nil
}
- text := string(n.Text(source))
+ text := ctx.Buffer.Bytes()[ctx.pos:]
+ ctx.Buffer.Truncate(ctx.pos)
err := h.ImageRenderer.Render(
w,
page: ctx.DocumentContext().Document,
destination: string(n.Destination),
title: string(n.Title),
- text: text,
- plainText: text,
+ text: string(text),
+ plainText: string(n.Text(source)),
},
)
ctx.AddIdentity(h.ImageRenderer.GetIdentity())
- return ast.WalkSkipChildren, err
+ return ast.WalkContinue, err
}