Skip to content

Commit 1b4dd43

Browse files
jmooringbep
authored andcommitted
markup/goldmark: Align blockquote default output with Goldmark
Closes #14046
1 parent 4414ef7 commit 1b4dd43

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

‎markup/goldmark/blockquotes/blockquotes.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (r *htmlRenderer) renderBlockquote(w util.BufWriter, src []byte, node ast.N
6969
return ast.WalkContinue, nil
7070
}
7171

72-
text := strings.TrimSpace(ctx.PopRenderedString())
72+
text := ctx.PopRenderedString()
7373

7474
ordinal := ctx.GetAndIncrementOrdinal(ast.KindBlockquote)
7575

@@ -90,7 +90,7 @@ func (r *htmlRenderer) renderBlockquote(w util.BufWriter, src []byte, node ast.N
9090
// tag if the first line of the blockquote content does not have a
9191
// closing p tag. At some point we might want to move this to the
9292
// parser.
93-
before, after, found := strings.Cut(text, "\n")
93+
before, after, found := strings.Cut(strings.TrimSpace(text), "\n")
9494
if found {
9595
if strings.HasSuffix(before, "</p>") {
9696
text = after
@@ -173,7 +173,7 @@ func (c *blockquoteContext) Text() hstring.HTML {
173173
var blockQuoteAlertRe = regexp.MustCompile(`^<p>\[!([a-zA-Z]+)\](-|\+)?[^\S\r\n]?([^\n]*)\n?`)
174174

175175
func resolveBlockQuoteAlert(s string) blockQuoteAlert {
176-
m := blockQuoteAlertRe.FindStringSubmatch(s)
176+
m := blockQuoteAlertRe.FindStringSubmatch(strings.TrimSpace(s))
177177
if len(m) == 4 {
178178
title := strings.TrimSpace(m[3])
179179
title = strings.TrimSuffix(title, "</p>")

‎markup/goldmark/blockquotes/blockquotes_integration_test.go‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package blockquotes_test
1515

1616
import (
1717
"path/filepath"
18+
"strings"
1819
"testing"
1920

2021
"github.com/gohugoio/hugo/hugolib"
@@ -76,7 +77,7 @@ title: "p1"
7677
"Blockquote Alert: |<p>This is a note with some whitespace after the alert type.</p>|alert|",
7778
"Blockquote Alert: |<p>This is a tip.</p>",
7879
"Blockquote Alert: |<p>This is a caution with some whitespace before the alert type.</p>|alert|",
79-
"Blockquote: |<p>A regular blockquote.</p>|regular|",
80+
"Blockquote: |<p>A regular blockquote.</p>\n|regular|",
8081
"Blockquote Alert Attributes: |<p>This is a tip with attributes.</p>|map[class:foo bar id:baz]|",
8182
filepath.FromSlash("/content/p1.md:19:3"),
8283
"Blockquote Alert Page: |<p>This is a tip with attributes.</p>|p1|p1|",
@@ -248,6 +249,37 @@ title: home
248249
"AlertType: fourteen|AlertTitle: title|Text: <p><img src=\"a.jpg\" alt=\"alt\"></p>|",
249250
"AlertType: fifteen|AlertTitle: <em>title</em>|Text: |",
250251
"AlertType: sixteen|AlertTitle: <em>title</em>|Text: <p>line one</p>|",
251-
"AlertType: |AlertTitle: |Text: <p>seventeen</p>|",
252+
"AlertType: |AlertTitle: |Text: <p>seventeen</p>\n|",
252253
)
253254
}
255+
256+
// Issue14046
257+
func TestBlockquoteDefaultOutput(t *testing.T) {
258+
t.Parallel()
259+
260+
files := `
261+
-- hugo.toml --
262+
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
263+
-- content/p1.md --
264+
---
265+
title: p1
266+
---
267+
> foo
268+
-- layouts/page.html --
269+
|{{ .Content }}|
270+
-- xxx --
271+
<blockquote>
272+
{{ .Text }}
273+
</blockquote>
274+
`
275+
276+
want := "|<blockquote>\n<p>foo</p>\n</blockquote>\n|"
277+
278+
b := hugolib.Test(t, files)
279+
b.AssertFileContent("public/p1/index.html", want) // fail
280+
281+
files = strings.ReplaceAll(files, "xxx", "layouts/_markup/render-blockquote.html")
282+
283+
b = hugolib.Test(t, files)
284+
b.AssertFileContent("public/p1/index.html", want)
285+
}

0 commit comments

Comments
 (0)