From f43cb875566e3b127a8f5e4ac82721ba4d2a8f4e Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sat, 3 May 2025 23:05:25 +0400 Subject: [PATCH] refac --- .../components/common/RichTextInput.svelte | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index bfcc37860..2b506670a 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -387,9 +387,33 @@ selectTemplate(); } } else { - if (value !== editor.getHTML()) { - editor.commands.setContent(value); - selectTemplate(); + if (raw) { + if (value !== editor.getHTML()) { + editor.commands.setContent(value); + selectTemplate(); + } + } else { + if ( + value !== + turndownService + .turndown( + (preserveBreaks + ? editor.getHTML().replace(/

<\/p>/g, '
') + : editor.getHTML() + ).replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0')) + ) + .replace(/\u00a0/g, ' ') + ) { + preserveBreaks + ? editor.commands.setContent(value) + : editor.commands.setContent( + marked.parse(value.replaceAll(`\n
`, `
`), { + breaks: false + }) + ); // Update editor content + + selectTemplate(); + } } } };