html-dom-parser
Version:
HTML to DOM parser.
27 lines (26 loc) • 927 B
JavaScript
const require_utilities = require("./utilities.js");
let domhandler = require("domhandler");
let htmlparser2 = require("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.DomHandler(void 0, options);
new htmlparser2.Parser(handler, options).end(html);
return require_utilities.unsetRootParent(handler.dom);
}
//#endregion
exports.default = HTMLDOMParser;
//# sourceMappingURL=html-to-dom.js.map