mirror of
https://github.com/postlight/mercury-parser
synced 2024-11-17 03:25:31 +00:00
fix: removeEmpty shouldn't remove elements with images or iframes inside
This commit is contained in:
parent
c63f500433
commit
38c90d239e
@ -1,7 +1,7 @@
|
||||
export default function removeEmpty($article, $) {
|
||||
$article.find('p').each((index, p) => {
|
||||
const $p = $(p);
|
||||
if ($p.text().trim() === '') $p.remove();
|
||||
if ($p.find('iframe, img').length === 0 && $p.text().trim() === '') $p.remove();
|
||||
});
|
||||
|
||||
return $;
|
||||
|
@ -27,5 +27,13 @@ describe('removeEmpty($)', () => {
|
||||
const result = removeEmpty($('*').first(), $);
|
||||
assertClean(result.html(), HTML.removeEmptyP.after);
|
||||
});
|
||||
|
||||
it('does not remove empty p tags containing an iframe', () => {
|
||||
const html = '<div><p><span><iframe src="foo"></iframe></span></p></div>';
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
const result = removeEmpty($('*').first(), $);
|
||||
assertClean(result.html(), html);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user