fix: removeEmpty shouldn't remove elements with images or iframes inside

pull/17/head
Adam Pash 8 years ago
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…
Cancel
Save