1+ import { visit } from "unist-util-visit"
2+
13/**
24 * Counts the number of markdown headings in the given text.
35 * Matches headings from level 1 to 6 (e.g. #, ##, ###, etc.).
@@ -32,7 +34,7 @@ export type AlertType = (typeof ALERT_TYPES)[number]
3234
3335// Matches a leading alert marker like "[!NOTE]" (case-insensitive) optionally
3436// followed by trailing whitespace/newline on the first line of a blockquote.
35- const ALERT_MARKER_REGEX = / ^ \ [! ( n o t e | t i p | i m p o r t a n t | w a r n i n g | c a u t i o n ) \ ][ ^ \S \r \ n] * \r ? \n ? / i
37+ const ALERT_MARKER_REGEX = new RegExp ( `^\\ [!(${ ALERT_TYPES . join ( "|" ) } )\\ ][^\\S\\r\\ n]*\\ r?\\n?` , "i" )
3638
3739/**
3840 * remark plugin that detects GitHub-style alerts inside blockquotes
@@ -47,24 +49,8 @@ const ALERT_MARKER_REGEX = /^\[!(note|tip|important|warning|caution)\][^\S\r\n]*
4749 * normal blockquotes continue to render exactly as before.
4850 */
4951export function remarkGithubAlerts ( ) {
50- return ( tree : any ) => {
51- walkAlertBlockquotes ( tree )
52- }
53- }
54-
55- function walkAlertBlockquotes ( node : any ) : void {
56- if ( ! node || typeof node !== "object" ) {
57- return
58- }
59-
60- if ( node . type === "blockquote" ) {
61- annotateAlertBlockquote ( node )
62- }
63-
64- if ( Array . isArray ( node . children ) ) {
65- for ( const child of node . children ) {
66- walkAlertBlockquotes ( child )
67- }
52+ return ( tree : Parameters < typeof visit > [ 0 ] ) => {
53+ visit ( tree , "blockquote" , annotateAlertBlockquote )
6854 }
6955}
7056
0 commit comments