Skip to content

Commit

Permalink
fix: Additional cases related to #21
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Mar 6, 2023
1 parent aca1fba commit 6e137f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/converters/fromHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ const convertFromHTML = (input, defaultTextBlock) => {
el.removeChild(child);
result.push(blockFromElement(child, defaultTextBlock));
} else {
keepWrapper = true;
keepWrapper = shouldKeepWrapper(child);
}
// Check for grandchild nodes containing elementsWithConverters
const gchildren = child.childNodes;
for (const gchild of gchildren) {
if (elementsWithConverters.includes(gchild.tagName)) {
child.removeChild(gchild);
result.push(blockFromElement(gchild, defaultTextBlock));
}
}
}
if (keepWrapper) {
Expand Down
30 changes: 30 additions & 0 deletions src/converters/fromHtml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,34 @@ describe('convertFromHTML parsing image', () => {
},
]);
});

describe('inside a nested span element containing valid text', () => {
const html = '<p><span><img src="image.jpeg" />text</span></p>';

const result = convertFromHTML(html, 'slate');
expect(result).toHaveLength(2);
expect(result[0]).toEqual({
'@type': 'image',
align: 'center',
alt: '',
size: 'l',
title: '',
url: 'image.jpeg',
});
});
});

describe('inside a nested span element, with a sibling containing valid text', () => {
const html = '<p><span><img src="image.jpeg" /></span><span>text</span></p>';

const result = convertFromHTML(html, 'slate');
expect(result).toHaveLength(2);
expect(result[0]).toEqual({
'@type': 'image',
align: 'center',
alt: '',
size: 'l',
title: '',
url: 'image.jpeg',
});
});

0 comments on commit 6e137f9

Please sign in to comment.