From: Joe Mooring Date: Mon, 13 Oct 2025 19:12:28 +0000 (-0700) Subject: markup/goldmark: Align blockquote default output with Goldmark X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=1b4dd436dd1be2b3b65cba51b9c1ee23b9b05196;p=brevno-suite%2Fhugo markup/goldmark: Align blockquote default output with Goldmark Closes #14046 --- diff --git a/markup/goldmark/blockquotes/blockquotes.go b/markup/goldmark/blockquotes/blockquotes.go index 539cd1875..c82b9f8f4 100644 --- a/markup/goldmark/blockquotes/blockquotes.go +++ b/markup/goldmark/blockquotes/blockquotes.go @@ -69,7 +69,7 @@ func (r *htmlRenderer) renderBlockquote(w util.BufWriter, src []byte, node ast.N return ast.WalkContinue, nil } - text := strings.TrimSpace(ctx.PopRenderedString()) + text := ctx.PopRenderedString() ordinal := ctx.GetAndIncrementOrdinal(ast.KindBlockquote) @@ -90,7 +90,7 @@ func (r *htmlRenderer) renderBlockquote(w util.BufWriter, src []byte, node ast.N // tag if the first line of the blockquote content does not have a // closing p tag. At some point we might want to move this to the // parser. - before, after, found := strings.Cut(text, "\n") + before, after, found := strings.Cut(strings.TrimSpace(text), "\n") if found { if strings.HasSuffix(before, "

") { text = after @@ -173,7 +173,7 @@ func (c *blockquoteContext) Text() hstring.HTML { var blockQuoteAlertRe = regexp.MustCompile(`^

\[!([a-zA-Z]+)\](-|\+)?[^\S\r\n]?([^\n]*)\n?`) func resolveBlockQuoteAlert(s string) blockQuoteAlert { - m := blockQuoteAlertRe.FindStringSubmatch(s) + m := blockQuoteAlertRe.FindStringSubmatch(strings.TrimSpace(s)) if len(m) == 4 { title := strings.TrimSpace(m[3]) title = strings.TrimSuffix(title, "

") diff --git a/markup/goldmark/blockquotes/blockquotes_integration_test.go b/markup/goldmark/blockquotes/blockquotes_integration_test.go index 6f7914d07..f9d308538 100644 --- a/markup/goldmark/blockquotes/blockquotes_integration_test.go +++ b/markup/goldmark/blockquotes/blockquotes_integration_test.go @@ -15,6 +15,7 @@ package blockquotes_test import ( "path/filepath" + "strings" "testing" "github.com/gohugoio/hugo/hugolib" @@ -76,7 +77,7 @@ title: "p1" "Blockquote Alert: |

This is a note with some whitespace after the alert type.

|alert|", "Blockquote Alert: |

This is a tip.

", "Blockquote Alert: |

This is a caution with some whitespace before the alert type.

|alert|", - "Blockquote: |

A regular blockquote.

|regular|", + "Blockquote: |

A regular blockquote.

\n|regular|", "Blockquote Alert Attributes: |

This is a tip with attributes.

|map[class:foo bar id:baz]|", filepath.FromSlash("/content/p1.md:19:3"), "Blockquote Alert Page: |

This is a tip with attributes.

|p1|p1|", @@ -248,6 +249,37 @@ title: home "AlertType: fourteen|AlertTitle: title|Text:

\"alt\"

|", "AlertType: fifteen|AlertTitle: title|Text: |", "AlertType: sixteen|AlertTitle: title|Text:

line one

|", - "AlertType: |AlertTitle: |Text:

seventeen

|", + "AlertType: |AlertTitle: |Text:

seventeen

\n|", ) } + +// Issue14046 +func TestBlockquoteDefaultOutput(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['home','rss','section','sitemap','taxonomy','term'] +-- content/p1.md -- +--- +title: p1 +--- +> foo +-- layouts/page.html -- +|{{ .Content }}| +-- xxx -- +
+{{ .Text }} +
+` + + want := "|
\n

foo

\n
\n|" + + b := hugolib.Test(t, files) + b.AssertFileContent("public/p1/index.html", want) // fail + + files = strings.ReplaceAll(files, "xxx", "layouts/_markup/render-blockquote.html") + + b = hugolib.Test(t, files) + b.AssertFileContent("public/p1/index.html", want) +}