mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
26 lines
718 B
JavaScript
26 lines
718 B
JavaScript
import { decodeHTML5 } from "entities";
|
|
import { DOMParser } from "linkedom";
|
|
|
|
const RealDOMParser =
|
|
"window" in global && "DOMParser" in window
|
|
? new window.DOMParser()
|
|
: new DOMParser();
|
|
|
|
export const parseHTML = (input) =>
|
|
RealDOMParser.parseFromString(wrapIntoHTMLDocument(input), "text/html");
|
|
|
|
export function getDummyDocument() {
|
|
const doc = parseHTML("<div></div>");
|
|
return doc;
|
|
}
|
|
|
|
export function getInnerText(element) {
|
|
return decodeHTML5(element.innerText || element.textContent);
|
|
}
|
|
|
|
function wrapIntoHTMLDocument(input) {
|
|
if (input.includes("<body>")) return input;
|
|
|
|
return `<!doctype html><html lang="en"><head><title>Document Fragment</title></head><body>${input}</body></html>`;
|
|
}
|