Skip to content

Commit

Permalink
Misc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abrynos authored Mar 18, 2024
1 parent 42bd65c commit 03390e4
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/Markdig/Extensions/Bootstrap/BootstrapExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer)

private static void PipelineOnDocumentProcessed(MarkdownDocument document)
{
Span<char> upperKind = new char[16];
foreach (var node in document.Descendants())
{
if (node.IsInline)
Expand All @@ -61,22 +62,23 @@ private static void PipelineOnDocumentProcessed(MarkdownDocument document)
var attributes = node.GetAttributes();
attributes.AddClass("alert");
attributes.AddProperty("role", "alert");

Span<char> upperKind = new char[alertBlock.Kind.Length];
alertBlock.Kind.AsSpan().ToUpperInvariant(upperKind);
string? @class = upperKind switch
if (alertBlock.Kind.Length <= upperKind.Length)
{
"NOTE" => "alert-primary",
"TIP" => "alert-success",
"IMPORTANT" => "alert-info",
"WARNING" => "alert-warning",
"CAUTION" => "alert-danger",
_ => null,
};
alertBlock.Kind.AsSpan().ToUpperInvariant(upperKind);
string? @class = upperKind.Slice(0, alertBlock.Kind.Length) switch
{
"NOTE" => "alert-primary",
"TIP" => "alert-success",
"IMPORTANT" => "alert-info",
"WARNING" => "alert-warning",
"CAUTION" => "alert-danger",
_ => null,
};

if (@class is not null)
{
attributes.AddClass(@class);
if (@class is not null)
{
attributes.AddClass(@class);
}
}

var lastParagraph = alertBlock.Descendants().OfType<ParagraphBlock>().LastOrDefault();
Expand Down

0 comments on commit 03390e4

Please sign in to comment.