diff --git a/src/converters/fromHtml.js b/src/converters/fromHtml.js index 64a87ba..406a7b8 100644 --- a/src/converters/fromHtml.js +++ b/src/converters/fromHtml.js @@ -97,7 +97,7 @@ const extractElementsWithConverters = (el, defaultTextBlock, href) => { href = el.getAttribute('href'); } // First, traverse all childNodes - for (const child of el.childNodes) { + for (const child of Array.from(el.childNodes)) { const tmpResult = extractElementsWithConverters( child, defaultTextBlock, @@ -146,7 +146,7 @@ const convertFromHTML = (input, defaultTextBlock) => { // convert to blocks for (const el of elements) { - const children = el.childNodes; + const children = Array.from(el.childNodes); const href = el.getAttribute('href'); for (const child of children) { // With children nodes, we keep the wrapper only diff --git a/src/converters/fromHtml.test.js b/src/converters/fromHtml.test.js index 69b31e3..518f749 100644 --- a/src/converters/fromHtml.test.js +++ b/src/converters/fromHtml.test.js @@ -350,6 +350,30 @@ describe('convertFromHTML parsing image', () => { ]); }); + test('inside a block element with another image', () => { + const html = '
'; + + const result = convertFromHTML(html, 'slate'); + expect(result).toEqual([ + { + '@type': 'image', + align: 'center', + alt: '', + size: 'l', + title: '', + url: 'image1.jpg', + }, + { + '@type': 'image', + align: 'center', + alt: '', + size: 'l', + title: '', + url: 'image2.jpg', + }, + ]); + }); + test('inside a p element', () => { const html = '';