diff --git a/src/lib/utils/post-utils.ts b/src/lib/utils/post-utils.ts index e0d008ad..01dcee51 100644 --- a/src/lib/utils/post-utils.ts +++ b/src/lib/utils/post-utils.ts @@ -24,10 +24,16 @@ export function getTextColorForBackground(rgb: string): string { export const formatMarkdown = (content: string): string => { let md = content; if (md) { - // Replace single newline with "/n /n" if followed by a newline - md = md.replace(/\n(?=\n)/g, '\n \n'); - // Replace single newline with double newline if between two characters - md = md.replace(/\n(?=\S)/g, '\n\n'); + // Check if the content already contains valid Markdown patterns + const alreadyFormattedPattern = /\n \n/; + + // help the user by formatting the content if it's not already formatted + if (!alreadyFormattedPattern.test(md)) { + // Replace single newline with "/n /n" if followed by a newline + md = md.replace(/\n(?=\n)/g, '\n \n'); + // Replace single newline with double newline if between two characters + md = md.replace(/\n(?=\S)/g, '\n\n'); + } } return md; };