Skip to content

Instantly share code, notes, and snippets.

@whamtet
Created January 20, 2022 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whamtet/2a57add92612af254de6f7db5c1a76e7 to your computer and use it in GitHub Desktop.
Save whamtet/2a57add92612af254de6f7db5c1a76e7 to your computer and use it in GitHub Desktop.
Preprocess svgs
#!/opt/homebrew/bin/planck
(require '[planck.core :refer [*in* slurp]])
(require '[clojure.string :as string])
(require '[cljs.reader :refer [read-string]])
(def in (slurp *in*))
(def subsections
(map second
(re-seq #"d=\"([^\"]+)" in)))
(defn read-all [s]
(read-string (str "(" s ")")))
(defn eval-form [s]
(if (list? s) (eval s) s))
(defn eval-d-section [forms]
(->> forms
read-all
(map eval-form)
(string/join " ")))
(defn update-sections [s f subsections]
(reduce (fn [s subsection]
(.replace s subsection (f subsection)))
s
subsections))
(println
(update-sections in eval-d-section subsections))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment