Skip to content

Support character reference " in urls e.g. url("#foo") #1029

@rob-myers

Description

@rob-myers

The popular online SVG editor BoxySVG output files like:

<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
  <defs>
    <radialGradient gradientUnits="userSpaceOnUse" cx="50" cy="50" r="25" id="gradient-0">
      <stop offset="0" style="stop-color: rgb(84.706% 84.706% 84.706%)"/>
      <stop offset="1" style="stop-color: rgb(48.42% 48.42% 48.42%)"/>
    </radialGradient>
  </defs>
  <rect x="25" y="25" width="50" height="50"
     style="stroke: rgb(0, 0, 0); fill: url(&quot;#gradient-0&quot;);"
   />
</svg>

Please notice the:

fill: url(&quot;#gradient-0&quot;)

which is apparently valid SVG code although it is not valid CSS code.

Problem:

If we loadImage(svgPath) then drawImage(image) we get a black square i.e no gradient.

Changing url(&quot;#gradient-0&quot;) to url(#gradient-0), the gradient works as expected.

Request:

Handle this valid syntax in loadImage.

Technically, we can load SVG contents, remove such "character references" then construct a data-url. Preferably this would be handled automatically by @napi-rs/canvas, just like the npm module canvas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions