encode-svg-for-css.mjs 548 B

1234567891011121314151617181920
  1. import { encodeSVGforURL } from './url.mjs';
  2. function encodeSvgForCss(svg) {
  3. let useSvg = svg.startsWith("<svg>") ? svg.replace("<svg>", "<svg >") : svg;
  4. if (!useSvg.includes(" xmlns:xlink=") && useSvg.includes(" xlink:")) {
  5. useSvg = useSvg.replace(
  6. "<svg ",
  7. '<svg xmlns:xlink="http://www.w3.org/1999/xlink" '
  8. );
  9. }
  10. if (!useSvg.includes(" xmlns=")) {
  11. useSvg = useSvg.replace(
  12. "<svg ",
  13. '<svg xmlns="http://www.w3.org/2000/svg" '
  14. );
  15. }
  16. return encodeSVGforURL(useSvg);
  17. }
  18. export { encodeSvgForCss };