mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
don't help user format markdown if content already contains correct empty line syntax
This commit is contained in:
@@ -24,10 +24,16 @@ export function getTextColorForBackground(rgb: string): string {
|
|||||||
export const formatMarkdown = (content: string): string => {
|
export const formatMarkdown = (content: string): string => {
|
||||||
let md = content;
|
let md = content;
|
||||||
if (md) {
|
if (md) {
|
||||||
// Replace single newline with "/n /n" if followed by a newline
|
// Check if the content already contains valid Markdown patterns
|
||||||
md = md.replace(/\n(?=\n)/g, '\n \n');
|
const alreadyFormattedPattern = /\n \n/;
|
||||||
// Replace single newline with double newline if between two characters
|
|
||||||
md = md.replace(/\n(?=\S)/g, '\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;
|
return md;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user