UNPKG

html-dom-parser

Version:
22 lines (21 loc) 725 B
import { formatDOM } from "./utilities.mjs"; import domparser from "./domparser.mjs"; //#region src/client/html-to-dom.ts const DIRECTIVE_REGEX = /<(![a-zA-Z\s]+)>/; /** * Parses HTML string to DOM nodes in browser. * * @param html - HTML markup. * @param options - Parser options. * @returns - DOM elements. */ function HTMLDOMParser(html, options) { if (typeof html !== "string") throw new TypeError("First argument must be a string"); if (!html) return []; const match = DIRECTIVE_REGEX.exec(html); const directive = match ? match[1] : void 0; return formatDOM(domparser(html, options?.trustedTypePolicy), null, directive); } //#endregion export { HTMLDOMParser as default }; //# sourceMappingURL=html-to-dom.mjs.map