From 0ede1afdbcb24635d975db74ba38d78af85ff0c5 Mon Sep 17 00:00:00 2001 From: Elizabeth Danzberger Date: Wed, 6 Mar 2024 15:36:47 -0500 Subject: [PATCH] fix: traverse through nodes in order to determine the correct copy-paste behavior Signed-off-by: Elizabeth Danzberger --- src/extensions/Markdown.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/extensions/Markdown.js b/src/extensions/Markdown.js index ba1b097003d..8a345e69282 100644 --- a/src/extensions/Markdown.js +++ b/src/extensions/Markdown.js @@ -108,7 +108,17 @@ const Markdown = Extension.create({ return parser.parseSlice(dom, { preserveWhitespace: true, context: $context }) }, clipboardTextSerializer: (slice) => { - return createMarkdownSerializer(this.editor.schema).serialize(slice.content) + const traverseNodes = (slice) => { + if (slice.content.childCount > 1) { + return createMarkdownSerializer(this.editor.schema).serialize(slice.content) + } else if (slice.isLeaf) { + return slice.textContent + } else { + traverseNodes(slice.content.firstChild) + } + } + + return traverseNodes(slice) }, transformPastedHTML, },