Skip to content

Commit

Permalink
fix: Fixed a bug where some nodes could be skipped after converting a…
Browse files Browse the repository at this point in the history
…n element to a block. (#42)
  • Loading branch information
davisagli authored Nov 20, 2023
1 parent 9369b46 commit 03f7b20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/converters/fromHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/converters/fromHtml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,30 @@ describe('convertFromHTML parsing image', () => {
]);
});

test('inside a block element with another image', () => {
const html = '<div><img src="image1.jpg"><img src="image2.jpg"></div>';

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 = '<p><img src="image.jpeg"></p>';

Expand Down

0 comments on commit 03f7b20

Please sign in to comment.