(defn render-element!
"Render an element vector as a HTML element."
[element *key sb]
(if (nothing? element)
(when *key
(let [key @*key]
(vswap! *key inc)
(append! sb "<!-- react-empty: " key " -->")))
(let [[tag id classes attrs children] (normalize-element element)]
(append! sb "<" tag)
(when-some [type (:type attrs)]
(append! sb " type=\"" type "\""))
(when (and (= "option" tag)
(= (get-value attrs) *select-value*))
(append! sb " selected=\"\""))
(when id
(append! sb " id=\"" id "\""))
(render-attrs! tag attrs sb)
(render-classes! classes sb)
(when *key
(when (== @*key 1)
(append! sb " data-reactroot=\"\""))
(append! sb " data-reactid=\"" @*key "\"")
(vswap! *key inc))
(if (= "select" tag)
(binding [*select-value* (get-value attrs)]
(render-content! tag attrs children *key sb))
(render-content! tag attrs children *key sb)))))