]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
markup/goldmark: Align blockquote default output with Goldmark
authorJoe Mooring <joe.mooring@veriphor.com>
Mon, 13 Oct 2025 19:12:28 +0000 (12:12 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 14 Oct 2025 07:38:29 +0000 (09:38 +0200)
Closes #14046

markup/goldmark/blockquotes/blockquotes.go
markup/goldmark/blockquotes/blockquotes_integration_test.go

index 539cd187590e76c92bb9e18d257ed0ae0ddc7f96..c82b9f8f4b599bec7552b687cbf44914cf6e2a98 100644 (file)
@@ -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, "</p>") {
                                text = after
@@ -173,7 +173,7 @@ func (c *blockquoteContext) Text() hstring.HTML {
 var blockQuoteAlertRe = regexp.MustCompile(`^<p>\[!([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, "</p>")
index 6f7914d07344e978ba09f6483b7703ca0c71faee..f9d308538bd4875708f4555c8dfd20868cf91d30 100644 (file)
@@ -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: |<p>This is a note with some whitespace after the alert type.</p>|alert|",
                "Blockquote Alert: |<p>This is a tip.</p>",
                "Blockquote Alert: |<p>This is a caution with some whitespace before the alert type.</p>|alert|",
-               "Blockquote: |<p>A regular blockquote.</p>|regular|",
+               "Blockquote: |<p>A regular blockquote.</p>\n|regular|",
                "Blockquote Alert Attributes: |<p>This is a tip with attributes.</p>|map[class:foo bar id:baz]|",
                filepath.FromSlash("/content/p1.md:19:3"),
                "Blockquote Alert Page: |<p>This is a tip with attributes.</p>|p1|p1|",
@@ -248,6 +249,37 @@ title: home
                "AlertType: fourteen|AlertTitle: title|Text: <p><img src=\"a.jpg\" alt=\"alt\"></p>|",
                "AlertType: fifteen|AlertTitle: <em>title</em>|Text: |",
                "AlertType: sixteen|AlertTitle: <em>title</em>|Text: <p>line one</p>|",
-               "AlertType: |AlertTitle: |Text: <p>seventeen</p>|",
+               "AlertType: |AlertTitle: |Text: <p>seventeen</p>\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 --
+<blockquote>
+{{ .Text }}
+</blockquote>
+`
+
+       want := "|<blockquote>\n<p>foo</p>\n</blockquote>\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)
+}