UNPKG

html-dom-parser

Version:
27 lines (26 loc) 886 B
import { unsetRootParent } from "./utilities.mjs"; import { DomHandler } from "domhandler"; import { Parser } from "htmlparser2"; //#region src/server/html-to-dom.ts /** * Parses HTML string to DOM nodes in Node.js. * * This is the same method as `require('htmlparser2').parseDOM` * * @see https://github.com/fb55/htmlparser2/blob/v9.0.0/src/index.ts#L44-L46 * @see https://github.com/fb55/domhandler/tree/v5.0.3#readme * * @param html - HTML markup. * @param options - Parser options. * @returns - DOM nodes. */ function HTMLDOMParser(html, options) { if (typeof html !== "string") throw new TypeError("First argument must be a string."); if (!html) return []; const handler = new DomHandler(void 0, options); new Parser(handler, options).end(html); return unsetRootParent(handler.dom); } //#endregion export { HTMLDOMParser as default }; //# sourceMappingURL=html-to-dom.mjs.map