Skip to content

Commit

Permalink
Make alert block headers case-invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrynos committed Mar 18, 2024
1 parent 391f376 commit b7ae04b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Markdig/Extensions/Alerts/AlertBlockRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ protected override void Write(HtmlRenderer renderer, AlertBlock obj)
/// <param name="kind">The kind of the alert to render</param>
public static void DefaultRenderKind(HtmlRenderer renderer, StringSlice kind)
{
string? html = kind.AsSpan() switch
Span<char> upperKind = stackalloc char[kind.Length];
kind.AsSpan().ToUpperInvariant(upperKind);
string? html = upperKind switch
{
"NOTE" => "<p class=\"markdown-alert-title\"><svg viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z\"></path></svg>Note</p>",
"TIP" => "<p class=\"markdown-alert-title\"><svg viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"M8 1.5c-2.363 0-4 1.69-4 3.75 0 .984.424 1.625.984 2.304l.214.253c.223.264.47.556.673.848.284.411.537.896.621 1.49a.75.75 0 0 1-1.484.211c-.04-.282-.163-.547-.37-.847a8.456 8.456 0 0 0-.542-.68c-.084-.1-.173-.205-.268-.32C3.201 7.75 2.5 6.766 2.5 5.25 2.5 2.31 4.863 0 8 0s5.5 2.31 5.5 5.25c0 1.516-.701 2.5-1.328 3.259-.095.115-.184.22-.268.319-.207.245-.383.453-.541.681-.208.3-.33.565-.37.847a.751.751 0 0 1-1.485-.212c.084-.593.337-1.078.621-1.489.203-.292.45-.584.673-.848.075-.088.147-.173.213-.253.561-.679.985-1.32.985-2.304 0-2.06-1.637-3.75-4-3.75ZM5.75 12h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM6 15.25a.75.75 0 0 1 .75-.75h2.5a.75.75 0 0 1 0 1.5h-2.5a.75.75 0 0 1-.75-.75Z\"></path></svg>Tip</p>",
Expand Down
4 changes: 2 additions & 2 deletions src/Markdig/Extensions/Alerts/AlertInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)

var start = slice.Start;
var end = start;
while (c.IsAlphaUpper())
while (c.IsAlpha())
{
end = slice.Start;
c = slice.NextChar();
Expand Down Expand Up @@ -86,7 +86,7 @@ public override bool Match(InlineProcessor processor, ref StringSlice slice)
}
break;
}
else if (!c.IsSpaceOrTab())
else if (!c.IsSpaceOrTab())
{
slice = saved;
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/Markdig/Extensions/Bootstrap/BootstrapExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ private static void PipelineOnDocumentProcessed(MarkdownDocument document)
var attributes = node.GetAttributes();
attributes.AddClass("alert");
attributes.AddProperty("role", "alert");
string? @class = alertBlock.Kind.AsSpan() switch

Span<char> upperKind = new char[alertBlock.Kind.Length];
alertBlock.Kind.AsSpan().ToUpperInvariant(upperKind);
string? @class = upperKind switch
{
"NOTE" => "alert-primary",
"TIP" => "alert-success",
Expand Down

0 comments on commit b7ae04b

Please sign in to comment.