xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.41k stars 456 forks source link

Add bootstrap alert renderer #782

Closed Abrynos closed 8 months ago

Abrynos commented 8 months ago

Thank you for considering the inclusion of this merge request.

Closes #781

For testing I used the following MD:

# TODO

> [!NOTE]
> This is the newly generated NOTE block
> 
> And this is the second paragraph

> [!TIP]
> This is the newly generated TIP block
>
> And this is the second paragraph

> [!IMPORTANT]
> This is the newly generated IMPORTANT block
>
> And this is the second paragraph

> [!WARNING]
> This is the newly generated WARNING block
>
> And this is the second paragraph

> [!CAUTION]
> This is the newly generated CAUTION block
> 
> And this is the second paragraph

To produce this HTML:

<h1 id="todo">TODO</h1>
<div class="markdown-alert markdown-alert-note alert alert-primary" role="alert">
<p>This is the newly generated NOTE block</p>
<p style="margin-bottom: 0">And this is the second paragraph</p>
</div>
<div class="markdown-alert markdown-alert-tip alert alert-success" role="alert">
<p>This is the newly generated TIP block</p>
<p style="margin-bottom: 0">And this is the second paragraph</p>
</div>
<div class="markdown-alert markdown-alert-important alert alert-info" role="alert">
<p>This is the newly generated IMPORTANT block</p>
<p style="margin-bottom: 0">And this is the second paragraph</p>
</div>
<div class="markdown-alert markdown-alert-warning alert alert-warning" role="alert">
<p>This is the newly generated WARNING block</p>
<p style="margin-bottom: 0">And this is the second paragraph</p>
</div>
<div class="markdown-alert markdown-alert-caution alert alert-danger" role="alert">
<p>This is the newly generated CAUTION block</p>
<p style="margin-bottom: 0">And this is the second paragraph</p>
</div>

Which (with my HTML header and footer) looks like this:

image

Abrynos commented 8 months ago

Oh and of course a screenshot with the light theme of bootstrap:

image

xoofx commented 8 months ago

Thanks!

MihaZupan commented 8 months ago

As a follow-up, I realize that GH allows the NOTE / TIP, etc. in any casing, not just all upper. We might want to match that in our Alert block logic.

Abrynos commented 8 months ago

As a follow-up, I realize that GH allows the NOTE / TIP, etc. in any casing, not just all upper. We might want to match that in our Alert block logic.

Good catch! Should I make another PR, @xoofx ?

xoofx commented 8 months ago

As a follow-up, I realize that GH allows the NOTE / TIP, etc. in any casing, not just all upper. We might want to match that in our Alert block logic.

Good catch! Should I make another PR, @xoofx ?

Sure, go ahead. 🙂