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