linkifyjs icon indicating copy to clipboard operation
linkifyjs copied to clipboard

linkify-html breaks SVGs by removing self closing tags

Open ymhr opened this issue 3 years ago • 1 comments

linkfy-html removes self closing tags from any HTML it runs on, for example it will turn <br /> into <br>. In most cases this seems OK, but when it comes to SVGs it completely breaks them.

I have created an example here of a very simple SVG: https://stackblitz.com/edit/js-zhcfrd?file=index.js

On the top is the SVG rendering correctly, on the bottom is the result of passing it through linkify-html first.

The only difference is that the self-closing tag character (/) as been removed from both rect elements. Here's a text diff: https://www.diffchecker.com/giHtpROO

Here is a screenshot for users who may not be able to view the link Screenshot 2022-01-26 at 11 15 15

I think a decent solution to this would be an option to disable the removal of the slash, but I am open to alternative solutions.

It's also worth noting that:

  1. There are no links to linkify in this text, but the library still alters the HTML
  2. Even if the ignoreTags property is set to ['svg', 'rect'] the issue still occurs.

ymhr avatar Jan 26 '22 11:01 ymhr

Hi @ymhr, thanks for reporting. This will be fixed in the next major release of Linkify (v4). It's available now in a beta release:

npm install linkifyjs@beta
npm install linkify-html@beta

nfrasser avatar Jan 30 '22 21:01 nfrasser