diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go index 9c159f9cf35..0e942e6f57a 100644 --- a/markup/goldmark/render_hooks.go +++ b/markup/goldmark/render_hooks.go @@ -179,33 +179,6 @@ func renderAttributes(w util.BufWriter, skipClass bool, attributes ...ast.Attrib } } -// Fall back to the default Goldmark render funcs. Method below borrowed from: -// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404 -func (r *hookedRenderer) renderDefaultImage(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { - if !entering { - return ast.WalkContinue, nil - } - n := node.(*ast.Image) - _, _ = w.WriteString("`)
-	_, _ = w.Write(n.Text(source))
-	_ = w.WriteByte('") - } else { - _, _ = w.WriteString(">") - } - return ast.WalkSkipChildren, nil -} - func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { n := node.(*ast.Image) var h hooks.Renderers @@ -217,7 +190,7 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N } if !ok { - return r.renderDefaultImage(w, source, node, entering) + return r.renderImageDefault(w, source, node, entering) } if entering { @@ -247,24 +220,29 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N // Fall back to the default Goldmark render funcs. Method below borrowed from: // https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404 -func (r *hookedRenderer) renderDefaultLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { - n := node.(*ast.Link) - if entering { - _, _ = w.WriteString("') + } + if r.XHTML { + _, _ = w.WriteString(" />") } else { - _, _ = w.WriteString("") + _, _ = w.WriteString(">") } - return ast.WalkContinue, nil + return ast.WalkSkipChildren, nil } func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { @@ -278,7 +256,7 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No } if !ok { - return r.renderDefaultLink(w, source, node, entering) + return r.renderLinkDefault(w, source, node, entering) } if entering { @@ -309,6 +287,28 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No return ast.WalkContinue, err } +// Fall back to the default Goldmark render funcs. Method below borrowed from: +// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404 +func (r *hookedRenderer) renderLinkDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { + n := node.(*ast.Link) + if entering { + _, _ = w.WriteString("') + } else { + _, _ = w.WriteString("") + } + return ast.WalkContinue, nil +} + func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { if !entering { return ast.WalkContinue, nil @@ -324,7 +324,7 @@ func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node as } if !ok { - return r.renderDefaultAutoLink(w, source, node, entering) + return r.renderAutoLinkDefault(w, source, node, entering) } url := string(n.URL(source)) @@ -353,7 +353,7 @@ func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node as // Fall back to the default Goldmark render funcs. Method below borrowed from: // https://github.com/yuin/goldmark/blob/5588d92a56fe1642791cf4aa8e9eae8227cfeecd/renderer/html/html.go#L439 -func (r *hookedRenderer) renderDefaultAutoLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { +func (r *hookedRenderer) renderAutoLinkDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { n := node.(*ast.AutoLink) if !entering { return ast.WalkContinue, nil @@ -377,23 +377,6 @@ func (r *hookedRenderer) renderDefaultAutoLink(w util.BufWriter, source []byte, return ast.WalkContinue, nil } -func (r *hookedRenderer) renderDefaultHeading(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { - n := node.(*ast.Heading) - if entering { - _, _ = w.WriteString("') - } else { - _, _ = w.WriteString("\n") - } - return ast.WalkContinue, nil -} - func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { n := node.(*ast.Heading) var h hooks.Renderers @@ -405,7 +388,7 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast } if !ok { - return r.renderDefaultHeading(w, source, node, entering) + return r.renderHeadingDefault(w, source, node, entering) } if entering { @@ -438,6 +421,23 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast return ast.WalkContinue, err } +func (r *hookedRenderer) renderHeadingDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { + n := node.(*ast.Heading) + if entering { + _, _ = w.WriteString("') + } else { + _, _ = w.WriteString("\n") + } + return ast.WalkContinue, nil +} + type links struct { }