Timothy Jaeryang Baek 5 月之前
父节点
当前提交
f43cb87556
共有 1 个文件被更改,包括 27 次插入3 次删除
  1. 27 3
      src/lib/components/common/RichTextInput.svelte

+ 27 - 3
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><\/p>/g, '<br/>')
+								: 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<br/>`, `<br/>`), {
+									breaks: false
+								})
+							); // Update editor content
+
+					selectTemplate();
+				}
 			}
 		}
 	};