don't help user format markdown if content already contains correct empty line syntax

This commit is contained in:
Tom (plebeius.eth)
2024-08-28 21:51:03 +02:00
parent e04eb3bb5c
commit 21f75c1db1
+10 -4
View File
@@ -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;
};