Skip to content

Commit

Permalink
Fix readme template RX to handle double markers
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Jan 16, 2025
1 parent 3d6e5de commit d66990f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/tools/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const slugify = (string: string) => {
export const replaceInBetween = (content: string, mark: string, injection: string) => {
const escapedMark = mark.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const escapedInjection = injection.replace(/\$/g, '$$$$');
const rx = new RegExp(`${escapedMark}[\\S\\s]*${escapedMark}`, 'gm');
const rx = new RegExp(
`${escapedMark}([\\S\\s](?!${escapedMark}))*(\\s|\\S)?${escapedMark}`,
'gm',
);
return content.replace(rx, `${mark}\n${escapedInjection}\n${mark}`);
};

Expand Down

0 comments on commit d66990f

Please sign in to comment.