Skip to content

Commit

Permalink
Fix stray end p tag in Obsidian callout titles
Browse files Browse the repository at this point in the history
Closes #12828
  • Loading branch information
bep committed Sep 5, 2024
1 parent 792a22f commit a189798
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion markup/goldmark/blockquotes/blockquotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ var blockQuoteAlertRe = regexp.MustCompile(`^<p>\[!([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, "</p>")
return blockQuoteAlert{
typ: strings.ToLower(m[1]),
sign: m[2],
title: m[3],
title: title,
}
}

Expand Down
13 changes: 9 additions & 4 deletions markup/goldmark/blockquotes/blockquotes_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ title: "Home"
> [!danger]
> Do not approach or handle without protective gear.
> [!tip] Callouts can have custom titles
> Like this one.
Expand All @@ -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 --
Expand All @@ -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</p>|AlertSign: |",
"AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text: <p>Yes!",
"AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|",
"AlertType: tip|AlertTitle: Title-only callout|AlertSign: |",
"AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>\n|",
"AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>\n|",
"AlertType: danger|AlertTitle: |AlertSign: |Text: <p>Do not approach or handle without protective gear.</p>\n|",
"AlertTitle: Can callouts be nested?|",
"AlertTitle: You can even use multiple layers of nesting.|",
)
}
2 changes: 1 addition & 1 deletion markup/goldmark/blockquotes/blockquotes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func TestResolveBlockQuoteAlert(t *testing.T) {
}

for i, test := range tests {
c.Assert(resolveBlockQuoteAlert("<p>"+test.input), qt.Equals, test.expected, qt.Commentf("Test %d", i))
c.Assert(resolveBlockQuoteAlert("<p>"+test.input+"</p>"), qt.Equals, test.expected, qt.Commentf("Test %d", i))
}
}

0 comments on commit a189798

Please sign in to comment.