     [">"]))
 
 (def html-strategy {
-  :serialize-attribute-pair (create-serialize-attribute-pair "\"")
-  :write-empty-element-close html-empty-element-writer
-  })
+                    :serialize-attribute-pair (create-serialize-attribute-pair "\"")
+                    :write-empty-element-close html-empty-element-writer
+                    })
 
 (defn serialize-html
   "Serializes a seq of DOM nodes representing a complete document (as with serialize-xml) but with HTML


(def char-to-entity-map
  (merge
    ; Start with whitespace plus all ASCII printable
    (reduce #(assoc %1 (char %2) (char %2)) {}
      (concat [9 10 13 32 33 \' \"] (range 35 38) (range 40 126)))
    ; Then merge in the characters that must be XML entities
    {
      \< "&lt;"
      \> "&gt;"
      \& "&amp;"
      }))

(defn char-to-entity
  "Converts a single character to an entity, returning the entity or the original character."
  [ch]
  (or
    (char-to-entity-map ch)
    (format "&#x%x;" (int ch))))

(defn encode-string
  "Encodes a string, replacing all non-ASCII characters with XML escape codes. In addition,
  unsafe characters are replaced with HTML entities."
  [s]
  ; Could rewrite to more efficiently determine if out == s
  ; Perhaps a regexp to see if encoding is necessary?
  (let [out (apply str (map #(char-to-entity %) (seq s)))]
    (if (= s out) s out)))


(defprotocol ToAttributeValueString
  "Converts an attribute value to a string. It is not necessary to apply quotes (those come at a later stage)."
  ; TODO control over quotes inside the value string; I think
  (to-attribute-value-string [value]
    "Converts the value to a string that can be safely streamed as an attribute value."))


;;; and limitations under the License.

(ns
    cascade.dom
  "DOM node structure, rendering and manipulation"
  (:import
   (clojure.lang Keyword Sequential))
  (:require
   (clojure [zip :as z] [string :as str]))
  (:use
   (cascade fail utils)))

;;; TODO: For testing purposes (i.e., to get consistent results across JVMs, etc.)
;;; it may be necessary to sort attributes when rendering (but I'd rather not bother
