@@ -719,11 +719,18 @@ function replace_blank_lines(html: string) {
719
719
}
720
720
721
721
const delimiter_substitutes = {
722
- '---' : ' ' ,
723
- '+++' : ' ' ,
724
- ':::' : ' '
722
+ '---' : ' ' ,
723
+ '+++' : ' ' ,
724
+ ':::' : ' '
725
725
} ;
726
726
727
+ const delimiter_patterns = Object . fromEntries (
728
+ Object . entries ( delimiter_substitutes ) . map ( ( [ key , substitute ] ) => [
729
+ key ,
730
+ new RegExp ( `${ substitute } ([^ ][^]+?)${ substitute } ` , 'g' )
731
+ ] )
732
+ ) ;
733
+
727
734
function highlight_spans ( content : string , classname : string ) {
728
735
return content
729
736
. split ( '\n' )
@@ -878,13 +885,13 @@ async function syntax_highlight({
878
885
. replace ( ' tabindex="0"' , '' ) ;
879
886
880
887
html = html
881
- . replace ( / { 13 } ( [ ^ ] [ ^ ] + ? ) { 13 } / g , ( _ , content ) => {
888
+ . replace ( delimiter_patterns [ '---' ] , ( _ , content ) => {
882
889
return highlight_spans ( content , 'highlight remove' ) ;
883
890
} )
884
- . replace ( / { 11 } ( [ ^ ] [ ^ ] + ? ) { 11 } / g , ( _ , content ) => {
891
+ . replace ( delimiter_patterns [ '+++' ] , ( _ , content ) => {
885
892
return highlight_spans ( content , 'highlight add' ) ;
886
893
} )
887
- . replace ( / { 9 } ( [ ^ ] [ ^ ] + ? ) { 9 } / g , ( _ , content ) => {
894
+ . replace ( delimiter_patterns [ ':::' ] , ( _ , content ) => {
888
895
return highlight_spans ( content , 'highlight' ) ;
889
896
} ) ;
890
897
0 commit comments