Created
January 20, 2022 05:55
-
-
Save whamtet/2a57add92612af254de6f7db5c1a76e7 to your computer and use it in GitHub Desktop.
Preprocess svgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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