From a189798ff094880d09d1259e3ffecd73451c2fce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?=
Date: Thu, 5 Sep 2024 10:46:47 +0200
Subject: [PATCH] Fix stray end p tag in Obsidian callout titles
Closes #12828
---
markup/goldmark/blockquotes/blockquotes.go | 4 +++-
.../blockquotes/blockquotes_integration_test.go | 13 +++++++++----
markup/goldmark/blockquotes/blockquotes_test.go | 2 +-
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/markup/goldmark/blockquotes/blockquotes.go b/markup/goldmark/blockquotes/blockquotes.go
index f6d1a590ee0..f9d518850af 100644
--- a/markup/goldmark/blockquotes/blockquotes.go
+++ b/markup/goldmark/blockquotes/blockquotes.go
@@ -164,10 +164,12 @@ var blockQuoteAlertRe = regexp.MustCompile(`^\[!([a-zA-Z]+)\](-|\+)?[^\S\r\n]
func resolveBlockQuoteAlert(s string) blockQuoteAlert {
m := blockQuoteAlertRe.FindStringSubmatch(s)
if len(m) == 4 {
+ title := strings.TrimSpace(m[3])
+ title = strings.TrimRight(title, "
")
return blockQuoteAlert{
typ: strings.ToLower(m[1]),
sign: m[2],
- title: m[3],
+ title: title,
}
}
diff --git a/markup/goldmark/blockquotes/blockquotes_integration_test.go b/markup/goldmark/blockquotes/blockquotes_integration_test.go
index af3c1fba49a..1f671df2b20 100644
--- a/markup/goldmark/blockquotes/blockquotes_integration_test.go
+++ b/markup/goldmark/blockquotes/blockquotes_integration_test.go
@@ -123,7 +123,6 @@ title: "Home"
> [!danger]
> Do not approach or handle without protective gear.
-
> [!tip] Callouts can have custom titles
> Like this one.
@@ -135,6 +134,10 @@ title: "Home"
> [!faq]+ Foldable callout
> Yes! In a foldable callout, the contents are hidden when the callout is collapsed
+> [!info] Can callouts be nested?
+> > [!important] Yes!, they can.
+> > > [!tip] You can even use multiple layers of nesting.
+
-- layouts/index.html --
{{ .Content }}
-- layouts/_default/_markup/render-blockquote.html --
@@ -145,9 +148,11 @@ AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|AlertSign: {{ .AlertSi
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!",
- "AlertType: faq|AlertTitle: Foldable callout|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|",
+ "AlertTitle: Can callouts be nested?|",
+ "AlertTitle: You can even use multiple layers of nesting.|",
)
}
diff --git a/markup/goldmark/blockquotes/blockquotes_test.go b/markup/goldmark/blockquotes/blockquotes_test.go
index 8b948af08c1..067cf366e75 100644
--- a/markup/goldmark/blockquotes/blockquotes_test.go
+++ b/markup/goldmark/blockquotes/blockquotes_test.go
@@ -63,6 +63,6 @@ func TestResolveBlockQuoteAlert(t *testing.T) {
}
for i, test := range tests {
- c.Assert(resolveBlockQuoteAlert(""+test.input), qt.Equals, test.expected, qt.Commentf("Test %d", i))
+ c.Assert(resolveBlockQuoteAlert("
"+test.input+"
"), qt.Equals, test.expected, qt.Commentf("Test %d", i))
}
}