Created
August 17, 2015 11:52
-
-
Save uroybd/ce5b3ee3d9cb7facc19f to your computer and use it in GitHub Desktop.
Filter html
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
(use 'pl.danieljanus.tagsoup) | |
(use 'hiccup.core) | |
(defn parser [input] | |
(pl.danieljanus.tagsoup/parse | |
(java.io.ByteArrayInputStream. | |
(.getBytes | |
(slurp input))))) | |
(defn dissoc-all [dmap keys] | |
(apply dissoc dmap keys)) | |
(defn soap [element keys] | |
(cond | |
(map? element) (dissoc-all element keys) | |
(= (type []) (type element)) (mapv identity (map #(soap % keys) element)) | |
:else element)) | |
(defn sanitzer [parsed_input keys] | |
(mapv identity (map #(soap % keys) parsed_input))) | |
(defn html-o-matic | |
"Input: A file containing html data, output: another file containing filtered html data & optionally keys to filter" | |
([input output] | |
(html-o-matic input output :class :style :id)) | |
([input output & keys] | |
(let [veckeys (mapv identity keys)] | |
(with-open [w | |
(clojure.java.io/writer output)] | |
(.write w | |
(hiccup.core/html (sanitzer (parser input) veckeys))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment