From 7145b3e413a5263be16005bd4d1b7ed1ba29d9c2 Mon Sep 17 00:00:00 2001 From: Betty Steger Date: Thu, 30 Nov 2023 19:40:07 +0100 Subject: [PATCH] fix: pasting list with inline formats https://github.com/editor-js/nested-list/issues/26 --- src/index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index aba7b72c..2c3a6d51 100644 --- a/src/index.js +++ b/src/index.js @@ -235,10 +235,16 @@ export default class NestedList { return children.map((child) => { // get subitems if they exist. const subItemsWrapper = child.querySelector(`:scope > ${tagToSearch}`); - // get subitems. - const subItems = subItemsWrapper ? getPastedItems(subItemsWrapper) : []; - // get text content of the li element. - const content = child?.firstChild?.textContent || ''; + + let subItems = []; + let content = child?.innerHTML || ''; + + if (subItemsWrapper) { + // get subitems. + subItems = getPastedItems(subItemsWrapper); + // get html content of the li element, but without the ul/ol elements. + content = content.replace(subItemsWrapper.outerHTML, ''); + } return { content,