File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ async function main() {
4646 // save the file
4747 fse . outputFileSync (
4848 `./${ plugin . link } .md` ,
49- `${ headerSnippet } \n\n${ repoSnippet } \n\n${ data . trim ( ) } `
49+ `${ headerSnippet } \n\n${ repoSnippet } \n\n${ transformNoteStyle ( data ) } `
5050 )
5151 log ( chalk . green ( `File saved for plugin: ${ plugin . name } ` ) )
5252 }
@@ -80,4 +80,38 @@ async function main() {
8080 }
8181}
8282
83+ function transformNoteStyle ( content ) {
84+ // transforms note styles for vitepress
85+ const debug = false ;
86+ const NOTE_RE = / ^ > \s + \* { 2 } ( [ ^ \* ] + ) \* { 2 } : ? [ ^ \S \r \n ] + ( .+ (?: \n > .* ) * ) / gim;
87+ let match_ ;
88+ const containerTypeMap = {
89+ 'note' : 'tip' ,
90+ 'warning' : 'warning' ,
91+ }
92+
93+ while ( match_ = NOTE_RE . exec ( content ) ) {
94+ let [ match , title , cont ] = match_ ;
95+
96+ debug && console . log ( {
97+ match, title, cont
98+ } )
99+
100+ // normalize title
101+ title = title . replace ( / : / g, '' ) ;
102+
103+ // replace "> " from multiline quotes
104+ cont = cont . replace ( / ^ > \s * / gim, '' ) ;
105+
106+ // generate replacement
107+ let containerType = containerTypeMap [ title . toLowerCase ( ) ] ?? 'tip' ;
108+ const replacement = `:::${ containerType } ${ title } \n\n${ cont } \n\n:::` ;
109+
110+ // replace the match with the replacement
111+ content = content . replace ( match , replacement ) ;
112+ }
113+
114+ return content ;
115+ }
116+
83117main ( )
You can’t perform that action at this time.
0 commit comments