Repository: gohugoio/hugo (language: go)

Issue:
build(deps): bump github.com/yuin/goldmark from 1.7.4 to 1.7.8
Bumps [github.com/yuin/goldmark](https://github.com/yuin/goldmark) from 1.7.4 to 1.7.8.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/yuin/goldmark/commit/d9c03f07f08c2d36f23afe52dda865f05320ac86"><code>d9c03f0</code></a> Deprecate Node.Text</li>
<li><a href="https://github.com/yuin/goldmark/commit/65dcf6cd0aadc37c2e4ddf73ff5dd4335760ed0a"><code>65dcf6c</code></a> Add warning to Node.Text GoDoc</li>
<li><a href="https://github.com/yuin/goldmark/commit/ad1565131ac59a62eca147ca3e56d178fdd28cc2"><code>ad15651</code></a> Fix <a href="https://redirect.github.com/yuin/goldmark/issues/470">#470</a></li>
<li><a href="https://github.com/yuin/goldmark/commit/bc993b4f59cfaa8cd8c37215272dbc018e820384"><code>bc993b4</code></a> Fix testcases</li>
<li><a href="https://github.com/yuin/goldmark/commit/41273a4d0725cd0f098184e01fee4e1a2516ae87"><code>41273a4</code></a> Fix EOF rendering</li>
<li><a href="https://github.com/yuin/goldmark/commit/d80ac9397c194fdc8cb1d5ceb4f764a11e67c980"><code>d80ac93</code></a> Merge pull request <a href="https://redirect.github.com/yuin/goldmark/issues/462">#462</a> from Andrew-Morozko/table_fix</li>
<li><a href="https://github.com/yuin/goldmark/commit/15000ac6a1a8f30e4bd600da0df06f9634f86782"><code>15000ac</code></a> Fix lint errors</li>
<li><a href="https://github.com/yuin/goldmark/commit/14d91f957fc5cbed83d9124da3bb128cac11f590"><code>14d91f9</code></a> Merge pull request <a href="https://redirect.github.com/yuin/goldmark/issues/432">#432</a> from dr2chase/master</li>
<li><a href="https://github.com/yuin/goldmark/commit/3847ca20c65e8baacae69bbae6a14dbf8a09c611"><code>3847ca2</code></a> lazy initialize html5entities</li>
<li><a href="https://github.com/yuin/goldmark/commit/697e44ce881f864c785b78bdce80b0b48c86d712"><code>697e44c</code></a> Fix <a href="https://redirect.github.com/yuin/goldmark/issues/464">#464</a>, Fix <a href="https://redirect.github.com/yuin/goldmark/issues/465">#465</a></li>
<li>Additional commits viewable in <a href="https://github.com/yuin/goldmark/compare/v1.7.4...v1.7.8">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/yuin/goldmark&package-manager=go_modules&previous-version=1.7.4&new-version=1.7.8)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Discussion / hints:

Fix patch:
diff --git a/go.mod b/go.mod
index 4b1d53a1b24..ed3599c978a 100644
--- a/go.mod
+++ b/go.mod
@@ -70,7 +70,7 @@ require (
 	github.com/tdewolff/minify/v2 v2.20.37
 	github.com/tdewolff/parse/v2 v2.7.15
 	github.com/tetratelabs/wazero v1.8.1
-	github.com/yuin/goldmark v1.7.4
+	github.com/yuin/goldmark v1.7.8
 	github.com/yuin/goldmark-emoji v1.0.4
 	go.uber.org/automaxprocs v1.5.3
 	gocloud.dev v0.39.0
diff --git a/go.sum b/go.sum
index cc8b2368399..541718b42de 100644
--- a/go.sum
+++ b/go.sum
@@ -478,6 +478,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
 github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
 github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
 github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
+github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
+github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
 github.com/yuin/goldmark-emoji v1.0.4 h1:vCwMkPZSNefSUnOW2ZKRUjBSD5Ok3W78IXhGxxAEF90=
 github.com/yuin/goldmark-emoji v1.0.4/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
 go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go
index ea3bbc4ae9b..823a43c9d76 100644
--- a/markup/goldmark/convert.go
+++ b/markup/goldmark/convert.go
@@ -43,6 +43,7 @@ import (
 )
 
 const (
+	// Don't change this. This pattern is lso used in the image render hooks.
 	internalAttrPrefix = "_h__"
 )
 
diff --git a/markup/goldmark/internal/render/context.go b/markup/goldmark/internal/render/context.go
index b8cf9ba54ef..cd64fc94498 100644
--- a/markup/goldmark/internal/render/context.go
+++ b/markup/goldmark/internal/render/context.go
@@ -16,9 +16,13 @@ package render
 import (
 	"bytes"
 	"math/bits"
+	"strings"
 	"sync"
 
+	bp "github.com/gohugoio/hugo/bufferpool"
+
 	htext "github.com/gohugoio/hugo/common/text"
+	"github.com/gohugoio/hugo/tpl"
 
 	"github.com/gohugoio/hugo/markup/converter"
 	"github.com/gohugoio/hugo/markup/converter/hooks"
@@ -258,3 +262,30 @@ func (c *hookBase) Position() htext.Position {
 func (c *hookBase) PositionerSourceTarget() []byte {
 	return c.getSourceSample()
 }
+
+// TextPlain returns a plain text representation of the given node.
+// Goldmark's Node.Text was deprecated in 1.7.8.
+func TextPlain(n ast.Node, source []byte) string {
+	buf := bp.GetBuffer()
+	defer bp.PutBuffer(buf)
+
+	for c := n.FirstChild(); c != nil; c = c.NextSibling() {
+		textPlainTo(c, source, buf)
+	}
+	return buf.String()
+}
+
+func textPlainTo(c ast.Node, source []byte, buf *bytes.Buffer) {
+	if c == nil {
+		return
+	}
+	switch c := c.(type) {
+	case *ast.RawHTML:
+		s := strings.TrimSpace(tpl.StripHTML(string(c.Segments.Value(source))))
+		buf.WriteString(s)
+	case *ast.Text:
+		buf.Write(c.Segment.Value(source))
+	default:
+		textPlainTo(c.FirstChild(), source, buf)
+	}
+}
diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go
index bacb41a37fb..12cf0045528 100644
--- a/markup/goldmark/render_hooks.go
+++ b/markup/goldmark/render_hooks.go
@@ -200,7 +200,7 @@ func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.N
 				destination:      string(n.Destination),
 				title:            string(n.Title),
 				text:             hstring.HTML(text),
-				plainText:        string(n.Text(source)),
+				plainText:        render.TextPlain(n, source),
 				AttributesHolder: attributes.New(attrs, attributes.AttributesOwnerGeneral),
 			},
 			ordinal: ordinal,
@@ -223,7 +223,7 @@ func (r *hookedRenderer) filterInternalAttributes(attrs []ast.Attribute) []ast.A
 }
 
 // Fall back to the default Goldmark render funcs. Method below borrowed from:
-// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404
+// https://github.com/yuin/goldmark
 func (r *hookedRenderer) renderImageDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
 	if !entering {
 		return ast.WalkContinue, nil
@@ -234,7 +234,7 @@ func (r *hookedRenderer) renderImageDefault(w util.BufWriter, source []byte, nod
 		_, _ = w.Write(util.EscapeHTML(util.URLEscape(n.Destination, true)))
 	}
 	_, _ = w.WriteString(`" alt="`)
-	_, _ = w.Write(nodeToHTMLText(n, source))
+	r.renderTexts(w, source, n)
 	_ = w.WriteByte('"')
 	if n.Title != nil {
 		_, _ = w.WriteString(` title="`)
@@ -242,8 +242,7 @@ func (r *hookedRenderer) renderImageDefault(w util.BufWriter, source []byte, nod
 		_ = w.WriteByte('"')
 	}
 	if n.Attributes() != nil {
-		attrs := r.filterInternalAttributes(n.Attributes())
-		attributes.RenderASTAttributes(w, attrs...)
+		html.RenderAttributes(w, n, html.ImageAttributeFilter)
 	}
 	if r.XHTML {
 		_, _ = w.WriteString(" />")
@@ -289,7 +288,7 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No
 			destination:      string(n.Destination),
 			title:            string(n.Title),
 			text:             hstring.HTML(text),
-			plainText:        string(n.Text(source)),
+			plainText:        render.TextPlain(n, source),
 			AttributesHolder: attributes.Empty,
 		},
 	)
@@ -297,6 +296,79 @@ func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.No
 	return ast.WalkContinue, err
 }
 
+// Borrowed from Goldmark's HTML renderer.
+func (r *hookedRenderer) renderTexts(w util.BufWriter, source []byte, n ast.Node) {
+	for c := n.FirstChild(); c != nil; c = c.NextSibling() {
+		if s, ok := c.(*ast.String); ok {
+			_, _ = r.renderString(w, source, s, true)
+		} else if t, ok := c.(*ast.Text); ok {
+			_, _ = r.renderText(w, source, t, true)
+		} else {
+			r.renderTexts(w, source, c)
+		}
+	}
+}
+
+// Borrowed from Goldmark's HTML renderer.
+func (r *hookedRenderer) renderString(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
+	if !entering {
+		return ast.WalkContinue, nil
+	}
+	n := node.(*ast.String)
+	if n.IsCode() {
+		_, _ = w.Write(n.Value)
+	} else {
+		if n.IsRaw() {
+			r.Writer.RawWrite(w, n.Value)
+		} else {
+			r.Writer.Write(w, n.Value)
+		}
+	}
+	return ast.WalkContinue, nil
+}
+
+// Borrowed from Goldmark's HTML renderer.
+func (r *hookedRenderer) renderText(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
+	if !entering {
+		return ast.WalkContinue, nil
+	}
+	n := node.(*ast.Text)
+	segment := n.Segment
+	if n.IsRaw() {
+		r.Writer.RawWrite(w, segment.Value(source))
+	} else {
+		value := segment.Value(source)
+		r.Writer.Write(w, value)
+		if n.HardLineBreak() || (n.SoftLineBreak() && r.HardWraps) {
+			if r.XHTML {
+				_, _ = w.WriteString("<br />\n")
+			} else {
+				_, _ = w.WriteString("<br>\n")
+			}
+		} else if n.SoftLineBreak() {
+			// TODO(bep) we use these methods a fallback to default rendering when no image/link hooks are defined.
+			// I don't think the below is relevant in these situations, but if so, we need to create a PR
+			// upstream to export softLineBreak.
+			/*if r.EastAsianLineBreaks != html.EastAsianLineBreaksNone && len(value) != 0 {
+				sibling := node.NextSibling()
+				if sibling != nil && sibling.Kind() == ast.KindText {
+					if siblingText := sibling.(*ast.Text).Value(source); len(siblingText) != 0 {
+						thisLastRune := util.ToRune(value, len(value)-1)
+						siblingFirstRune, _ := utf8.DecodeRune(siblingText)
+						if r.EastAsianLineBreaks.softLineBreak(thisLastRune, siblingFirstRune) {
+							_ = w.WriteByte('\n')
+						}
+					}
+				}
+			} else {
+				_ = w.WriteByte('\n')
+			}*/
+			_ = w.WriteByte('\n')
+		}
+	}
+	return ast.WalkContinue, nil
+}
+
 // 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) {
@@ -443,7 +515,7 @@ func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast
 			level:            n.Level,
 			anchor:           string(anchor),
 			text:             hstring.HTML(text),
-			plainText:        string(n.Text(source)),
+			plainText:        render.TextPlain(n, source),
 			AttributesHolder: attributes.New(n.Attributes(), attributes.AttributesOwnerGeneral),
 		},
 	)
@@ -478,21 +550,3 @@ func (e *links) Extend(m goldmark.Markdown) {
 		util.Prioritized(newLinkRenderer(e.cfg), 100),
 	))
 }
-
-// Borrowed from Goldmark.
-func nodeToHTMLText(n ast.Node, source []byte) []byte {
-	var buf bytes.Buffer
-	for c := n.FirstChild(); c != nil; c = c.NextSibling() {
-		if s, ok := c.(*ast.String); ok && s.IsCode() {
-			buf.Write(s.Text(source))
-		} else if !c.HasChildren() {
-			buf.Write(util.EscapeHTML(c.Text(source)))
-			if t, ok := c.(*ast.Text); ok && t.SoftLineBreak() {
-				buf.WriteByte('\n')
-			}
-		} else {
-			buf.Write(nodeToHTMLText(c, source))
-		}
-	}
-	return buf.Bytes()
-}


Test patch: