The HTML string to convert
A DOM Document object
const doc = createDOM("<html><body><h1>Hello, world!</h1></body></html>");
// Returns: Document object
export function createDOM(html: string): Document {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
if (!doc) {
throw new Error("Failed to parse HTML");
}
return doc;
}
Converts an HTML string to a DOM Document object.