File tree 4 files changed +76
-0
lines changed
4 files changed +76
-0
lines changed Original file line number Diff line number Diff line change @@ -2725,6 +2725,41 @@ def run(self, text):
2725
2725
return self .admonitions_re .sub (self .sub , text )
2726
2726
2727
2727
2728
+ class Alerts (Extra ):
2729
+ '''
2730
+ Markdown Alerts as per
2731
+ https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
2732
+ '''
2733
+
2734
+ name = 'alerts'
2735
+ order = (), (Stage .BLOCK_QUOTES , )
2736
+
2737
+ alert_re = re .compile (r'''
2738
+ <blockquote>\s*
2739
+ <p>
2740
+ \[!(?P<type>NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]
2741
+ (?P<closing_tag></p>[ \t]*\n?)?
2742
+ (?P<contents>[\s\S]+?)
2743
+ </blockquote>
2744
+ ''' , re .X
2745
+ )
2746
+
2747
+ def test (self , text ):
2748
+ return "<blockquote>" in text
2749
+
2750
+ def sub (self , match : re .Match ) -> str :
2751
+ typ = match ["type" ].lower ()
2752
+ heading = f"<em>{ match ['type' ].title ()} </em>"
2753
+ contents = match ["contents" ].strip ()
2754
+ if match ["closing_tag" ]:
2755
+ return f'<div class="alert { typ } ">\n { heading } \n { contents } \n </div>'
2756
+ else :
2757
+ return f'<div class="alert { typ } ">\n { heading } \n <p>{ contents } \n </div>'
2758
+
2759
+ def run (self , text ):
2760
+ return self .alert_re .sub (self .sub , text )
2761
+
2762
+
2728
2763
class _BreaksExtraOpts (TypedDict , total = False ):
2729
2764
'''Options for the `Breaks` extra'''
2730
2765
on_backslash : bool
@@ -3501,6 +3536,7 @@ def test(self, text):
3501
3536
3502
3537
# Register extras
3503
3538
Admonitions .register ()
3539
+ Alerts .register ()
3504
3540
Breaks .register ()
3505
3541
CodeFriendly .register ()
3506
3542
FencedCodeBlocks .register ()
Original file line number Diff line number Diff line change
1
+ < div class ="alert note ">
2
+ < em > Note</ em >
3
+ < p > Useful information that users should know, even when skimming content.</ p >
4
+ </ div >
5
+
6
+ < div class ="alert tip ">
7
+ < em > Tip</ em >
8
+ < p > Helpful advice for doing things better or more easily.</ p >
9
+ </ div >
10
+
11
+ < div class ="alert important ">
12
+ < em > Important</ em >
13
+ < p > Key information users need to know to achieve their goal.</ p >
14
+ </ div >
15
+
16
+ < div class ="alert warning ">
17
+ < em > Warning</ em >
18
+ < p > Urgent info that needs immediate user attention to avoid problems.</ p >
19
+ </ div >
20
+
21
+ < div class ="alert caution ">
22
+ < em > Caution</ em >
23
+ < p > Advises about risks or negative outcomes of certain actions.</ p >
24
+ </ div >
Original file line number Diff line number Diff line change
1
+ {"extras": ["alerts"]}
Original file line number Diff line number Diff line change
1
+ > [!NOTE]
2
+ > Useful information that users should know, even when skimming content.
3
+
4
+ > [!TIP]
5
+ > Helpful advice for doing things better or more easily.
6
+
7
+ > [!IMPORTANT]
8
+ > Key information users need to know to achieve their goal.
9
+
10
+ > [!WARNING]
11
+ > Urgent info that needs immediate user attention to avoid problems.
12
+
13
+ > [!CAUTION]
14
+ >
15
+ > Advises about risks or negative outcomes of certain actions.
You can’t perform that action at this time.
0 commit comments