clean-html
clean-html copied to clipboard
img tag gets removed when using remove-empty-tags
trafficstars
When I use the remove-empty-tags option with any tag, img always gets removed.
<p><img alt="" src="https://github.githubassets.com/images/modules/dashboard/copilot/bg.jpg"></p>
It's regardless of self closing or not, if I use even picture instead of img. They get always removed. Seems like a whitelist is processed under the hood!?
Any idea @dave-kennedy ?
currently I come up with an ugly hack, I do transform the img tags to a div with some dummy content:
const input = content.replace(
/<img(.+?src=[\'"]([^\'"]+)[\'"].*?)>/g,
"<div$1>IMAGE-HACK</div>", // hack to get images not removed
);
and replace it back after cleanup
.replace(
/\<div(.+?src=[\'"]([^\'"]+)[\'"].*?)\>IMAGE-HACK\<\/div>/g, // hack to get images added back
"<img$1 />",
)
Its a temporary solution.
Sorry it took me so long to get back to you on this. This is definitely a bug. Thanks for reporting!