@@ -343,21 +343,40 @@ let tags = {
343343 '<li>' : '- ' ,
344344 '</li>' : '' ,
345345 '<ul>' : '' ,
346- '</ul>' : '' ,
346+ '</ul>' : '\n ' ,
347347 ' ' : ' ' ,
348348}
349349
350350function parseTags ( input ) {
351351 let output = input ;
352352 for ( const [ key , value ] of Object . entries ( tags ) ) {
353- output = output . replace ( key , value ) ;
353+ output = output . replaceAll ( key , value ) ;
354354 }
355355
356- // Fix links
357- output = output . replace ( / < a h r e f = " ( [ ^ " ] + ) " > ( [ ^ < ] + ) < \/ a > / g, '[$2]($1)' ) ;
356+ // Fix Links
357+ const linkRegex = / < a h r e f = " ( [ ^ " ] + ) " > ( [ ^ < ] + ) < \/ a > / g;
358+ let match ;
359+ match = linkRegex . exec ( output ) ;
360+ while ( match != null ) {
361+ output = output . replace ( match [ 0 ] , `[${ match [ 2 ] } ](${ match [ 1 ] } )` ) ;
362+ match = linkRegex . exec ( output ) ;
363+ }
364+
365+ // Fix Links target black
366+ const linkTargetRegex = / < a h r e f = " ( [ ^ " ] + ) " t a r g e t = " _ b l a n k " > ( [ ^ < ] + ) < \/ a > / g;
367+ match = linkTargetRegex . exec ( output ) ;
368+ while ( match != null ) {
369+ output = output . replace ( match [ 0 ] , `[${ match [ 2 ] } ](${ match [ 1 ] } )` ) ;
370+ match = linkTargetRegex . exec ( output ) ;
371+ }
358372
359373 // Fix font color
360- output = output . replace ( / < f o n t c o l o r = " ( [ ^ " ] + ) " > ( [ ^ < ] + ) < \/ f o n t > / g, '$2' ) ;
374+ const fontRegex = / < f o n t c o l o r = " ( [ ^ " ] + ) " > ( [ ^ < ] + ) < \/ f o n t > / g;
375+ match = fontRegex . exec ( output ) ;
376+ while ( match != null ) {
377+ output = output . replace ( match [ 0 ] , match [ 2 ] ) ;
378+ match = fontRegex . exec ( output ) ;
379+ }
361380
362381 return output ;
363382}
0 commit comments