Skip to content
Permalink
Browse files

Update README.md

  • Loading branch information...
cure53 committed Oct 28, 2015
1 parent 6097e3f commit a527039b649fc4562e92307059a0c92e8d9ef7fb
Showing with 15 additions and 15 deletions.
  1. +15 −15 demos/README.md
@@ -400,22 +400,22 @@ DOMPurify can be used to sanitize SVGs, but there can be some issues with some o

Here is an example which works well for content generated by Illustrator:
```javascript
// Add a hook to post-process a sanitized SVG
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
// Fix namespaces added by Adobe Illustrator
node.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
node.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
});
// Add a hook to post-process a sanitized SVG
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
// Fix namespaces added by Adobe Illustrator
node.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
node.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
});
// Clean SVG string and allow the "filter" tag
var clean = DOMPurify.sanitize(dirty, {ADD_TAGS: ['filter']});
// Clean SVG string and allow the "filter" tag
var clean = DOMPurify.sanitize(dirty, {ADD_TAGS: ['filter']});
// Remove partial XML comment left in the HTML
var badTag = clean.indexOf(']>');
var pureSvg = clean.substring(badTag < 0 ? 0 : 5, clean.length);
// Remove partial XML comment left in the HTML
var badTag = clean.indexOf(']&gt;');
var pureSvg = clean.substring(badTag < 0 ? 0 : 5, clean.length);
// Show sanitized content in <img> element
var img = new Image();
img.src = "data:image/svg+xml;base64," + window.btoa(pureSvg);
document.getElementById('sanitized').appendChild(img);
// Show sanitized content in <img> element
var img = new Image();
img.src = "data:image/svg+xml;base64," + window.btoa(pureSvg);
document.getElementById('sanitized').appendChild(img);
```

0 comments on commit a527039

Please sign in to comment.
You can’t perform that action at this time.