From 9a4d2562371a16f1e95e8602029e563809b9ba89 Mon Sep 17 00:00:00 2001 From: vagusx Date: Tue, 25 Jul 2023 13:58:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8F=8D=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E5=AF=BC=E8=87=B4=E8=8A=82=E7=82=B9=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1=E5=9D=97=E4=BF=A1=E6=81=AF=E5=87=BA=E7=8E=B0=E4=BB=BB?= =?UTF-8?q?=E6=84=8F=E9=94=AE=E5=85=A5=E5=90=8E=E5=9B=9E=E5=88=A0=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E5=92=8C=E5=9B=BE=E7=89=87=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor/deserialize.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/editor/deserialize.ts b/src/components/editor/deserialize.ts index ef9ecbc4..cc01cf47 100644 --- a/src/components/editor/deserialize.ts +++ b/src/components/editor/deserialize.ts @@ -1,7 +1,8 @@ import { jsx } from 'slate-hyperscript'; -type JSXElement = ReturnType; -const deserialize = (el: Node): JSXElement | string | null => { +type SlateJSXElement = ReturnType; +const deserialize = (el: Node): SlateJSXElement | string | null => { + // 递归到 children 时直接返回 textContent string 格式 if (el.nodeType === 3) { return (el as Text).textContent; } else if (el.nodeType !== 1) { @@ -9,7 +10,7 @@ const deserialize = (el: Node): JSXElement | string | null => { } const htmlElement = el as HTMLElement; - let children: (JSXElement | string)[] = Array.from( + let children: (SlateJSXElement | string)[] = Array.from( htmlElement.childNodes, ).map(deserialize); @@ -46,7 +47,7 @@ const deserialize = (el: Node): JSXElement | string | null => { children, ); default: - return htmlElement.textContent || ''; + return jsx('element', { type: 'paragraph' }, [ htmlElement.textContent || '' ]); } };