clean-html icon indicating copy to clipboard operation
clean-html copied to clipboard

img tag gets removed when using remove-empty-tags

Open appinteractive opened this issue 3 years ago • 1 comments
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 ?

appinteractive avatar Sep 07 '22 14:09 appinteractive

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.

appinteractive avatar Sep 07 '22 14:09 appinteractive

Sorry it took me so long to get back to you on this. This is definitely a bug. Thanks for reporting!

dave-kennedy avatar Apr 07 '23 03:04 dave-kennedy