Created
August 29, 2020 23:15
-
-
Save tomhodgins/067966548544960d47ce9f62e7fc2988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deno Support | |
if ('Deno' in globalThis) { | |
globalThis.DOMParser = (await import('https://deno.land/x/deno_dom/deno-dom-wasm.ts')).DOMParser | |
} | |
// Node Support | |
if ('process' in globalThis) { | |
const jsdom = (await import('jsdom')).default.JSDOM | |
globalThis.DOMParser = class { | |
parseFromString(string = '', mode = '') { | |
return (new jsdom(string)).window.document | |
} | |
} | |
} | |
console.log( | |
new DOMParser() | |
.parseFromString(`one<p><b>two<p>three</b>`, 'text/html') | |
.body | |
.innerHTML | |
) | |
// Should log: one<p><b>two</b></p><p><b>three</b></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment