UNPKG

omim

Version:

Material Design for Omi.

34 lines (30 loc) 772 B
const parser = new DOMParser() export function htmlToVdom(html) { if(!html) return null return processNode(parser.parseFromString(`<div>${html}</div>`, "text/xml").childNodes[0]).children } function processNode(node) { if (node.nodeType === 1) { var i, child, attributes = {}, children = []; for (i = 0; (child = node.attributes[i]); ++i) { attributes[child.nodeName] = child.nodeValue; } for (i = 0; (child = node.childNodes[i]); ++i) { var vn = processNode(child) if (vn !== null) children.push(vn) } return { nodeName: node.tagName, attributes, children } } if (node.nodeType === 3) { const v = node.nodeValue.trim() if (v !== '') { return v } return null } }