Browse Source

fix: rich text input issue

Timothy Jaeryang Baek 4 months ago
parent
commit
bfdbb2df69
1 changed files with 9 additions and 5 deletions
  1. 9 5
      src/lib/components/common/RichTextInput.svelte

+ 9 - 5
src/lib/components/common/RichTextInput.svelte

@@ -191,15 +191,19 @@
 			onTransaction: () => {
 				// force re-render so `editor.isActive` works as expected
 				editor = editor;
-				const newValue = turndownService
+				let newValue = turndownService
 					.turndown(
-						(preserveBreaks
-							? editor.getHTML().replace(/<p><\/p>/g, '<br/>')
-							: editor.getHTML()
-						).replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'))
+						editor
+							.getHTML()
+							.replace(/<p><\/p>/g, '<br/>')
+							.replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'))
 					)
 					.replace(/\u00a0/g, ' ');
 
+				if (!preserveBreaks) {
+					newValue = newValue.replace(/<br\/>/g, '');
+				}
+
 				if (value !== newValue) {
 					value = newValue;