From 34373407b7778d66e2aaf009c6faeda5a1c2a866 Mon Sep 17 00:00:00 2001
From: Joe Mooring [!NOTE] " + text[strings.Index(text, "\n")+1:]
+ // Parse the blockquote content to determine the alert text. The alert
+ // text begins after the first newline, but we need to add an opening p
+ // 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(strings.TrimSpace(text), "\n")
+ if found {
+ if strings.HasSuffix(before, " " + after
+ }
+ } else {
+ text = ""
+ }
}
bqctx := &blockquoteContext{
@@ -165,7 +176,7 @@ func resolveBlockQuoteAlert(s string) blockQuoteAlert {
m := blockQuoteAlertRe.FindStringSubmatch(s)
if len(m) == 4 {
title := strings.TrimSpace(m[3])
- title = strings.TrimRight(title, "
\n but preserve leading paragraph.
- // We could possibly complicate this by moving this to the parser, but
- // keep it simple for now.
- text = "
This is a note with some whitespace after the alert type.
\n|alert|", + "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.
\n|alert|", + "Blockquote Alert: |This is a caution with some whitespace before the alert type.
|alert|", "Blockquote: |A regular blockquote.
\n|regular|", - "Blockquote Alert Attributes: |This is a tip with attributes.
\n|map[class:foo bar id:baz]|", - filepath.FromSlash("/content/p1.md:20:3"), - "Blockquote Alert Page: |This is a tip with attributes.
\n|p1|p1|", + "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|", // Issue 12767. - "Blockquote Alert: |Mixed case alert type.
\n|alert", + "Blockquote Alert: |Mixed case alert type.
|alert", ) } @@ -142,17 +138,113 @@ title: "Home" {{ .Content }} -- layouts/_default/_markup/render-blockquote.html -- AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|AlertSign: {{ .AlertSign | safeHTML }}|Text: {{ .Text }}| - + ` b := hugolib.Test(t, files) b.AssertFileContentExact("public/index.html", "AlertType: tip|AlertTitle: Callouts can have custom titles|AlertSign: |", "AlertType: tip|AlertTitle: Title-only callout|AlertSign: |", - "AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text:Yes! In a foldable callout, the contents are hidden when the callout is collapsed
\n|", - "AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|Text:Yes! In a foldable callout, the contents are hidden when the callout is collapsed
\n|", - "AlertType: danger|AlertTitle: |AlertSign: |Text:Do not approach or handle without protective gear.
\n|", + "AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text:Yes! In a foldable callout, the contents are hidden when the callout is collapsed
|", + "AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|Text:Yes! In a foldable callout, the contents are hidden when the callout is collapsed
|", + "AlertType: danger|AlertTitle: |AlertSign: |Text:Do not approach or handle without protective gear.
|", "AlertTitle: Can callouts be nested?|", "AlertTitle: You can even use multiple layers of nesting.|", ) } + +// Issue 12913 +// Issue 13119 +func TestBlockquoteRenderHookTextParsing(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +-- layouts/index.html -- +{{ .Content }} +-- layouts/_default/_markup/render-blockquote.html -- +AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|Text: {{ .Text }}| +-- content/_index.md -- +--- +title: home +--- + +> [!one] + +> [!two] title + +> [!three] +> line 1 + +> [!four] title +> line 1 + +> [!five] +> line 1 +> line 2 + +> [!six] title +> line 1 +> line 2 + +> [!seven] +> - list item + +> [!eight] title +> - list item + +> [!nine] +> line 1 +> - list item + +> [!ten] title +> line 1 +> - list item + +> [!eleven] +> line 1 +> - list item +> +> line 2 + +> [!twelve] title +> line 1 +> - list item +> +> line 2 + +> [!thirteen] +>  + +> [!fourteen] title +>  + +> [!fifteen] _title_ + +> [!sixteen] _title_ +> line one + +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/index.html", + "AlertType: one|AlertTitle: |Text: |", + "AlertType: two|AlertTitle: title|Text: |", + "AlertType: three|AlertTitle: |Text:line 1
|", + "AlertType: four|AlertTitle: title|Text:line 1
|", + "AlertType: five|AlertTitle: |Text:line 1\nline 2
|", + "AlertType: six|AlertTitle: title|Text:line 1\nline 2
|", + "AlertType: seven|AlertTitle: |Text:line 1
\nline 1
\nline 1
\nline 2
|", + "AlertType: twelve|AlertTitle: title|Text:line 1
\nline 2
|", + "AlertType: thirteen|AlertTitle: |Text:line one
|", + ) +}