tweb-i2p/src/helpers/dom/htmlToDocumentFragment.ts
2022-04-19 22:33:56 +03:00

14 lines
491 B
TypeScript

/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
export default function htmlToDocumentFragment(html: string | DocumentFragment) {
if(html instanceof DocumentFragment) return html;
const template = document.createElement('template');
html = html.trim(); // Never return a text node of whitespace as the result
template.innerHTML = html;
return template.content;
}