babashka 2026-09-28

Babashka Snippet to tidy html (adapted from Chatgpt)

(import '[org.jsoup Jsoup])

(defn tidy-html [path]
  (let [doc (Jsoup/parse (slurp path))]
    (spit path (.html doc))))
I'm sharing it because the original suggestion was not working

Original suggestion was below, but the https://jsoup.org/apidocs/org/jsoup/nodes/Document.OutputSettings is not part of Babashka and I am not sure if it is needed since the above works to tidy.

(import '[org.jsoup Jsoup])

(defn tidy-html [path]
  (let [doc (Jsoup/parse (slurp path))
        settings (.outputSettings doc)]
    (.prettyPrint settings true)
    (.indentAmount settings 2)
    (.outline settings true)
    (spit path (.html doc))))

It is nice because it saves me from installing random other tools!

Confirmation that it works with 1.13.225! Thanks!

👍 1