From b490221feb0ac56ddeee818e611e34c632da2455 Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Fri, 20 Dec 2024 11:26:45 +0100 Subject: [PATCH] improve buttons block conversion --- src/converters/fromDraftjs.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/converters/fromDraftjs.js b/src/converters/fromDraftjs.js index 90882a4..2db6ca3 100644 --- a/src/converters/fromDraftjs.js +++ b/src/converters/fromDraftjs.js @@ -279,17 +279,20 @@ const blocks = { (child, i) => `

${joinRecursively(child)}

`, ), buttons: (children, { keys }) => { - let html = children[0].filter((x) => x !== undefined); - const tag = parser.parseFromString(html, 'text/html'); + const data = children.map((child, i) => { + let html = child.flat().filter((x) => x !== undefined); + const tag = parser.parseFromString(html.join(''), 'text/html'); - tag.body.childNodes.forEach((node) => { - if (node.getAttribute) { - let css_class = node.getAttribute('class') || ''; - css_class += 'btn btn-primary inline-link'; - node.setAttribute('class', css_class); - } + tag.body.childNodes.forEach((node) => { + if (node.getAttribute) { + let css_class = node.getAttribute('class') || ''; + css_class += 'btn btn-primary inline-link'; + node.setAttribute('class', css_class); + } + }); + return tag.body.innerHTML; }); - return `

${tag.body.innerHTML}

`; + return `

${data.join('
')}

`; }, // 'code-block': (children, { keys }) => ( //