mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
f83846e054
Before this commit, a condition deemed always true made the building crash. The happened with TypeScript == 3.7.2 After this commit, the required typescript version has been changed, as well as the incriminated true condition
28 lines
719 B
TypeScript
28 lines
719 B
TypeScript
import { VNode, h } from "./vdom";
|
|
|
|
const parser = new DOMParser();
|
|
|
|
export function htmlToVDOM(html: string): VNode[] {
|
|
const doc = parser.parseFromString(html, "text/html");
|
|
const result: VNode[] = [];
|
|
for (let child of doc.body.childNodes) {
|
|
result.push(htmlToVNode(child));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function htmlToVNode(node: ChildNode): VNode {
|
|
if (!(node instanceof Element)) {
|
|
return { text: node.textContent! } as VNode;
|
|
}
|
|
const attrs = {};
|
|
for (let attr of node.attributes) {
|
|
attrs[attr.name] = attr.textContent;
|
|
}
|
|
const children: VNode[] = [];
|
|
for (let c of node.childNodes) {
|
|
children.push(htmlToVNode(c));
|
|
}
|
|
return h((node as Element).tagName, { attrs }, children);
|
|
}
|