@@ -174,6 +174,7 @@ function treeVisitor() {
174174 } ) ;
175175 visit ( tree , "text" , onText ) ;
176176 visit ( tree , "html" , onHtml ) ;
177+ visit ( tree , "blockquote" , onBlockquote ) ;
177178
178179 let jsonString = JSON . stringify ( headings [ 0 ] ) ;
179180 if ( jsonString ) {
@@ -239,6 +240,42 @@ function treeVisitor() {
239240 }
240241 }
241242 }
243+
244+ function onBlockquote ( node , index , parent ) {
245+ // use github-like Tip & Warning syntax
246+ // see https://github.com/orgs/community/discussions/16925
247+ const { children : childrenLevel1 } = node ;
248+ if ( ! childrenLevel1 . length || childrenLevel1 [ 0 ] . type !== "paragraph" ) {
249+ return ;
250+ }
251+
252+ const { children : childrenLevel2 } = childrenLevel1 [ 0 ] ;
253+ if ( ! childrenLevel2 . length || childrenLevel2 [ 0 ] . type !== "linkReference" ) {
254+ return ;
255+ }
256+
257+ const TIP_MARKERS = [ "!tip" , "!warning" ] ;
258+ const { identifier } = childrenLevel2 [ 0 ] ;
259+ if ( ! TIP_MARKERS . includes ( identifier ) ) {
260+ return ;
261+ }
262+
263+ if ( ! parent ) {
264+ return ;
265+ }
266+
267+ childrenLevel1 [ 0 ] . children = childrenLevel1 [ 0 ] . children . slice ( 1 ) ;
268+ const nodeTagOpen = {
269+ type : "html" ,
270+ value : `<Tip warning={${ identifier === "!warning" } }>\n\n` ,
271+ } ;
272+ const nodeTagClose = {
273+ type : "html" ,
274+ value : "\n\n</Tip>" ,
275+ } ;
276+ const nodes = [ nodeTagOpen , ...childrenLevel1 , nodeTagClose ] ;
277+ parent . children . splice ( index , 1 , ...nodes ) ;
278+ }
242279}
243280
244281const _mdsvexPreprocess = mdsvex ( {
0 commit comments