feat(markdown): when the user is publishing a comment, automatically format it to follow markdown rules

This commit is contained in:
Tom (plebeius.eth)
2024-08-27 18:46:42 +02:00
parent e9c7e868f2
commit c521ccbc2e
5 changed files with 31 additions and 33 deletions
+11
View File
@@ -20,3 +20,14 @@ export function getTextColorForBackground(rgb: string): string {
const brightness = r * 0.299 + g * 0.587 + b * 0.114;
return brightness > 125 ? 'black' : 'white';
}
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');
}
return md;
};