yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
649 stars 98 forks source link

Utilize DOMPurify hooks to preserve <use> elements in playground mode #156

Closed listopadiya closed 3 years ago

listopadiya commented 3 years ago

Closes #155.

<use> tags were filtered out after sanitization, but with DOMPurify hooks this problem can be solved (regular expression still filter out links to external resources in the interest of security).

Can be checked in playground with following SVG code:

<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
  <style type="text/css">
    use { fill: orange; }
  </style>
  <g class="special" style="fill: blue">
    <g id="face">
      <circle cx="50" cy="50" r="40" stroke="#000000" />
      <circle cx="30" cy="40" r="5" fill="#000000" />
      <circle cx="70" cy="40" r="5" fill="#000000" />
      <path
        fill="none"
        stroke="#000000"
        stroke-width="3"
        stroke-linecap="round"
        d="M30,60 C30,80 70,80 70,60" />
    </g>
  </g>
  <use xlink:href="#face" x="100" />
</svg>

Before PR image

After PR image