From de824badeed95eb7934e044aa716d7745b7a51d2 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 21 Jun 2022 21:31:44 +0800 Subject: [PATCH] tiptap: just return text for list node --- .../src/tiptap/core/extensions/clipboard.ts | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/packages/client/src/tiptap/core/extensions/clipboard.ts b/packages/client/src/tiptap/core/extensions/clipboard.ts index 74bd5e7..259a0a1 100644 --- a/packages/client/src/tiptap/core/extensions/clipboard.ts +++ b/packages/client/src/tiptap/core/extensions/clipboard.ts @@ -67,28 +67,36 @@ export const Clipboard = Extension.create({ const json = slice.content.toJSON(); const isSelectAll = slice.openStart === slice.openEnd && slice.openEnd === 0; + if (Array.isArray(json) && !isSelectAll) { + const type = json[0].type; + + // 列表项返回文字内容 + if (['bulletList', 'orderedList', 'taskList'].includes(type)) { + return slice.content.textBetween(0, slice.content.size, '\n\n'); + } + } + if (typeof json === 'object' || isSelectAll) { return extensionThis.options.prosemirrorToMarkdown({ content: slice.content, }); - } else { - const isText = isPureText(json) && !isSelectAll; - - if (isText) { - return slice.content.textBetween(0, slice.content.size, '\n\n'); - } - - const doc = slice.content; - - if (!doc) { - return ''; - } - - const content = extensionThis.options.prosemirrorToMarkdown({ - content: doc, - }); - return content; } + + const isText = isPureText(json) && !isSelectAll; + + if (isText) { + return slice.content.textBetween(0, slice.content.size, '\n\n'); + } + const doc = slice.content; + + if (!doc) { + return ''; + } + + const content = extensionThis.options.prosemirrorToMarkdown({ + content: doc, + }); + return content; }, }, }),