File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -6,10 +6,21 @@ import { INDEX_TAG } from '../constants.js';
66 * @returns The updated text
77 */
88export const findFirstParagraph = ( text : string ) : string => {
9- const regex = / ^ ( # # \s .+ ) \n { 1 , 3 } / gm;
10- const split = text . split ( regex ) ;
11- split . splice ( 1 , 0 , `<!-- ${ INDEX_TAG } -start -->\n<!-- ${ INDEX_TAG } -end -->\n\n` ) ;
12- return split . join ( '' ) ;
9+ const regex = / ^ ( # # \s .+ ) ( \n { 1 , 3 } ) / gm;
10+ const match = regex . exec ( text ) ;
11+
12+ if ( ! match ) {
13+ return text ;
14+ }
15+
16+ const matchStart = match . index ;
17+ const matchEnd = match . index + match [ 0 ] . length ;
18+
19+ const beforeMatch = text . substring ( 0 , matchStart ) ;
20+ const headingAndNewlines = match [ 0 ] ;
21+ const afterMatch = text . substring ( matchEnd ) ;
22+
23+ return `${ beforeMatch } <!-- ${ INDEX_TAG } -start -->\n<!-- ${ INDEX_TAG } -end -->\n\n${ headingAndNewlines } ${ afterMatch } ` ;
1324} ;
1425
1526/**
You can’t perform that action at this time.
0 commit comments