Created
October 13, 2021 17:12
-
-
Save shanewholloway/0b5df53acb93b0787f87b2344d7ad495 to your computer and use it in GitHub Desktop.
DOM parsing and serializing
This file contains 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
export function parse_html(raw_html_string) { | |
return new DOMParser() | |
.parseFromString(raw_html_string, 'text/html') } | |
export function dom_to_html_blob(dom) { | |
let html_doc = new XMLSerializer() | |
.serializeToString(dom) | |
return new Blob([html_doc], {type: 'text/html'}) } | |
export function dom_to_html_blob_url(dom) { | |
return URL.createObjectURL(dom_to_html_blob(dom)) } | |
export function dom_to_iframe(iframe, dom_document) { | |
let dest_doc = iframe.contentDocument | |
dest_doc.documentElement.replaceWith( | |
dest_doc.adoptNode( | |
dom_document.documentElement)) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment