Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute xlink:href redefined #151

Open
kamshory opened this issue Jan 31, 2023 · 1 comment
Open

Attribute xlink:href redefined #151

kamshory opened this issue Jan 31, 2023 · 1 comment

Comments

@kamshory
Copy link

When I place a PNG image in the document, it throws an error "Attribute xlink:href redefined". When I check the tag, there is a duplicate attribute xlink:href.
How to get rid of the duplication?

@julles007
Copy link

The Problem

I was able to pin down the issue to line 5355 in src/js/svgcanvas.js.

if (illutratorCompat && str.includes(" href=")) str = str.replace(" href=", " xlink:href=");

If the xml already has an xlink:href attribute AND an href attribute, the href becomes xlink:href.

SVG2 removes the xlink namespace altogether,
and this attribute is now deprecated.

The "real solution" to this would be to figure out how to stop xlink:href from being written in the first place. (I mean, if backwards-compatibility isn't an issue for you)
Oddly enough, removing this line

svgedit.utilities.setHref = function(elem, val) {
  elem.setAttributeNS(XLINKNS, "xlink:href", val); // this
  elem.setAttribute("href", val);
}

and/or this line

    image.setAttributeNS(xlinkns,'xlink:href',url);

doesn't solve it.

Working (but not ideal) Solution

Consider a PR that changes that line to

// make sure we don't already have an `xlink:href` attribute
if (illutratorCompat && str.includes(" href=") && !str.includes(" xlink:href=")) {
   str = str.replace(" href=", " xlink:href=");
  }

or simply "if it has both attributes don't do anything".

It solves the problem but feels hacky and wrong. Plus it might break other workflows?

So currently the entire image Base64 is written twice... once in the href attr and the other in the xlink namespace attr.
the xlink one can obviously be removed in the line after, but it's best not to create it at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants