#!/usr/bin/env lein-exec (leiningen.exec/deps '[[hiccup "1.0.3"] [guns.cli/optparse "1.0.1"]]) (require '[hiccup.core :as hiccup] '[hiccup.page :as page] '[clojure.string :as string] '[clojure.java.io :as io] '[clojure.data.xml :as xml] '[clojure.java.shell :as shell] '[guns.cli.optparse :refer [parse]]) ;;; ;;; XML <-> Hiccup conversion functions. ;;; (defn tidy "Add newlines and tab indents to hiccup form for pretty printing." ([form] (tidy form 1)) ([form indent] (if (and (vector? form) (some coll? form)) (let [nltab (apply str \newline (repeat indent \tab)) form' (reduce (fn [v f] (cond (vector? f) (conj v nltab (tidy f (inc indent))) (list? f) (into v (map #(list %1 (tidy %2 (inc indent))) (repeat nltab) f)) :else (conj v f))) [] form)] (conj form' (apply str \newline (repeat (dec indent) \tab)))) form))) (defn render-hiccup "Render xml node into a parsable hiccup string." ([node] (render-hiccup node 0)) ([node indent] (if (string? node) (format " \"%s\"" (-> node (string/replace #"(\\+\")" "\\\\\\\\$1") (string/replace #"(?