parse.js 504 B

12345678910111213141516171819
  1. /**
  2. * @param {string} content
  3. * @return {Element}
  4. */
  5. export default function (content) {
  6. const hasImportNode = !!document.importNode;
  7. const doc = new DOMParser().parseFromString(content, 'image/svg+xml').documentElement;
  8. /**
  9. * Fix for browser which are throwing WrongDocumentError
  10. * if you insert an element which is not part of the document
  11. * @see http://stackoverflow.com/a/7986519/4624403
  12. */
  13. if (hasImportNode) {
  14. return document.importNode(doc, true);
  15. }
  16. return doc;
  17. }