From d72607adb9f17d9cca5f71bd80a81305f676da36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 14 Aug 2024 16:57:18 +0200 Subject: [PATCH] markup/goldmark/blockquotes: Fix handling of lower/mixed case GitHub alerts Fixes #12767 --- markup/goldmark/blockquotes/blockquotes.go | 3 ++- .../goldmark/blockquotes/blockquotes_integration_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/markup/goldmark/blockquotes/blockquotes.go b/markup/goldmark/blockquotes/blockquotes.go index 2f5629d87..d26c92669 100644 --- a/markup/goldmark/blockquotes/blockquotes.go +++ b/markup/goldmark/blockquotes/blockquotes.go @@ -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(`^

\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]`) +// Note that GitHub's implementation is case-insensitive. +var gitHubAlertRe = regexp.MustCompile(`(?i)^

\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]`) // resolveGitHubAlert returns one of note, tip, warning, important or caution. // An empty string if no match. diff --git a/markup/goldmark/blockquotes/blockquotes_integration_test.go b/markup/goldmark/blockquotes/blockquotes_integration_test.go index 45c031098..e4447e5e9 100644 --- a/markup/goldmark/blockquotes/blockquotes_integration_test.go +++ b/markup/goldmark/blockquotes/blockquotes_integration_test.go @@ -68,6 +68,11 @@ title: "p1" > Note triggering showing the position. {showpos="true"} + +> [!nOtE] +> Mixed case alert type. + + ` b := hugolib.Test(t, files) @@ -79,6 +84,9 @@ title: "p1" "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|", + + // Issue 12767. + "Blockquote Alert: |

Mixed case alert type.

\n|alert", ) }