 
 (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;"
-      }))
+                                        ; 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))))
+   (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?
+                                        ; 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
+                                        ; 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."))
 

Does nothing if the targetted node can't be found. Returns a new
sequence of dom nodes.
dom-nodes
  A seq of nodes representing the document. The first element node is considered the root.
rules
  A seq of rules identifying where to place the new nodes. Each rule is a pair of values.
  The first value is a seq of element types (as keywords) to navigate down. The second
  value is a position (:before, :after:, :top, or :bottom). The first matching rule
  is used.
new-nodes
  The new nodes to insert in a position within the document."
  [dom-nodes rules new-nodes]
  (loop [result []
         queue dom-nodes]

         target-element (first path)
         remaining-path (rest path)]
    (lcond
     (nil? loc) nil
     :let [n (z/node loc)]
                                        ; if matching element?
     (and (element? n) (= (:name n) target-element))
                                        ; then either we've found it, or we need to go into the element and continue searching down.
     (if (empty? remaining-path)
       loc
       (recur (z/down loc) (first remaining-path) (rest remaining-path)))
     true (recur (z/right loc) target-element remaining-path))))

(defn update-dom
  "Updates the DOM using a DOM zipper, a position (:before, :after, :top, :bottom)
