Commits

Dominic Kexel committed 16dfc53

extract method

Comments (0)

Files changed (1)

src/mdclj/html.clj

 (ns mdclj.html
   (:use [mdclj.misc]))
 
-(defn output-element 
-  ([tag attributes bodyf]
+(defn- build-attr-str [attributes]
   (let [attr (clojure.string/join \space (for [[k v] attributes :when (seq v)] (str k \= \" v \")))
         attr (if (seq attributes) (str \space attr) attr)]
-    (str \< tag attr \> (bodyf) \< \/ tag \>)))
+    attr))
+
+(defn output-element 
+  ([tag attributes bodyf]
+    (str \< tag (build-attr-str attributes) \> (bodyf) "</" tag \>))
   ([tag attributes]
-  (let [attr (clojure.string/join \space (for [[k v] attributes :when (seq v)] (str k \= \" v \")))
-        attr (if (seq attributes) (str \space attr) attr)]
-    (str \< tag attr \space \/ \>))))
+    (str \< tag (build-attr-str attributes) " />")))
 
 (defn html-encode [text]
   (to-string (map #(str "&#x" (.toUpperCase (Integer/toHexString (int %))) \;) text)))