Diffdown is a real-time collaborative Markdown editor/previewer built on the AT Protocol diffdown.com
at main 28 lines 951 B view raw
1export default function crelt() { 2 var elt = arguments[0] 3 if (typeof elt == "string") elt = document.createElement(elt) 4 var i = 1, next = arguments[1] 5 if (next && typeof next == "object" && next.nodeType == null && !Array.isArray(next)) { 6 for (var name in next) if (Object.prototype.hasOwnProperty.call(next, name)) { 7 var value = next[name] 8 if (typeof value == "string") elt.setAttribute(name, value) 9 else if (value != null) elt[name] = value 10 } 11 i++ 12 } 13 for (; i < arguments.length; i++) add(elt, arguments[i]) 14 return elt 15} 16 17function add(elt, child) { 18 if (typeof child == "string") { 19 elt.appendChild(document.createTextNode(child)) 20 } else if (child == null) { 21 } else if (child.nodeType != null) { 22 elt.appendChild(child) 23 } else if (Array.isArray(child)) { 24 for (var i = 0; i < child.length; i++) add(elt, child[i]) 25 } else { 26 throw new RangeError("Unsupported child node: " + child) 27 } 28}