Skip to content

Commit

Permalink
markup/goldmark/blockquotes: Fix handling of lower/mixed case GitHub …
Browse files Browse the repository at this point in the history
…alerts

Fixes #12767
  • Loading branch information
bep committed Aug 14, 2024
1 parent 8323526 commit d72607a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion markup/goldmark/blockquotes/blockquotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ var _ hooks.PositionerSourceTargetProvider = (*blockquoteContext)(nil)
// https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
// Five types:
// [!NOTE], [!TIP], [!WARNING], [!IMPORTANT], [!CAUTION]
var gitHubAlertRe = regexp.MustCompile(`^<p>\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]`)
// Note that GitHub's implementation is case-insensitive.
var gitHubAlertRe = regexp.MustCompile(`(?i)^<p>\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]`)

// resolveGitHubAlert returns one of note, tip, warning, important or caution.
// An empty string if no match.
Expand Down
8 changes: 8 additions & 0 deletions markup/goldmark/blockquotes/blockquotes_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ title: "p1"
> Note triggering showing the position.
{showpos="true"}
> [!nOtE]
> Mixed case alert type.
`

b := hugolib.Test(t, files)
Expand All @@ -79,6 +84,9 @@ title: "p1"
"Blockquote Alert Attributes: |<p>This is a tip with attributes.</p>\n|map[class:foo bar id:baz]|",
filepath.FromSlash("/content/p1.md:20:3"),
"Blockquote Alert Page: |<p>This is a tip with attributes.</p>\n|p1|p1|",

// Issue 12767.
"Blockquote Alert: |<p>Mixed case alert type.</p>\n|alert",
)
}

Expand Down

0 comments on commit d72607a

Please sign in to comment.