feat: migrate to happy-dom from node-html-parser

This commit is contained in:
thecodrr
2022-04-19 00:04:57 +05:00
parent 3f6f5e6f9c
commit c9c57d87ab
6 changed files with 660 additions and 92 deletions

View File

@@ -1,14 +1,17 @@
import { parse } from "node-html-parser";
import { decodeHTML5 } from "entities";
import { Window } from "happy-dom";
export const parseHTML =
typeof DOMParser === "undefined"
? (input) => parse(input)
: (input) => new DOMParser().parseFromString(input, "text/html");
const RealDOMParser =
"window" in global && "DOMParser" in window
? new window.DOMParser()
: new new Window().DOMParser();
export const parseHTML = (input) =>
RealDOMParser.parseFromString(input, "text/html");
export function getDummyDocument() {
const doc = parseHTML("<div></div>");
return typeof DOMParser === "undefined" ? doc : doc;
return doc;
}
export function getInnerText(element) {