From 0055f3dcb67f40df45ceac775d1cee065787a2c3 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 1 Dec 2024 14:49:10 -0800 Subject: [PATCH] refac: rich text input --- .../components/common/RichTextInput.svelte | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/lib/components/common/RichTextInput.svelte b/src/lib/components/common/RichTextInput.svelte index 3f4925277..c9c8101c3 100644 --- a/src/lib/components/common/RichTextInput.svelte +++ b/src/lib/components/common/RichTextInput.svelte @@ -191,9 +191,14 @@ onTransaction: () => { // force re-render so `editor.isActive` works as expected editor = editor; - const newValue = turndownService.turndown( - preserveBreaks ? editor.getHTML().replace(/

<\/p>/g, '
') : editor.getHTML() - ); + const newValue = turndownService + .turndown( + (preserveBreaks + ? editor.getHTML().replace(/

<\/p>/g, '
') + : editor.getHTML() + ).replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0')) + ) + .replace(/\u00a0/g, ' '); if (value !== newValue) { value = newValue; @@ -332,9 +337,14 @@ $: if ( editor && value !== - turndownService.turndown( - preserveBreaks ? editor.getHTML().replace(/

<\/p>/g, '
') : editor.getHTML() - ) + turndownService + .turndown( + (preserveBreaks + ? editor.getHTML().replace(/

<\/p>/g, '
') + : editor.getHTML() + ).replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0')) + ) + .replace(/\u00a0/g, ' ') ) { editor.commands.setContent( marked.parse(value.replaceAll(`\n
`, `
`), {