babashka 2025-12-31

Do any of the various batteries included in Babashka have a way to decode XML entities? I want to turn something like "it's not that hard, surely" into "it's not that hard, surely". It seems like https://docs.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html#parseString%28java.lang.String%29 can do it, but that class isn't included in Babashka and would probably suck in a bunch of shit that you don't want. 😬

✅ 1

Indeed, I've avoided javax.xml so far :)

You could cheat by using clojure.data.xml:

(require '[clojure.data.xml :as xml])

(def xml "<root>Don&#x27;t</root>")

(-> (xml/parse-str xml) :content first)
;; => "Don't"

I hope you won't add this abomination to a PR in quickblog though... because then I'm responsible for it

you could also manually process the things with str/replace

user=> (org.jsoup.parser.Parser/unescapeEntities "don&#x27;t" false)
"don't"

💜 1
🎉 1
✅ 1

@highpressurecarsalesm Lovely! Thank you so much! 🎉

@borkdude Not everything is about quickblog, y'know. 😜

This is actually part of https://codeberg.org/jmglov/cljcastr, my latest bit of silliness.

It got complicated enough that I actually had to add some tests. 😭

cool, I was afraid my hack would backfire on me! :P

😂 1

Since when has a hack ever backfired? 😈

one person's hack is another person's main project

😂 1

I sometimes feel like my editor config is one my main projects, and like it's a collection of hacks 🙃

Haha, I can relate! Moving to Doom Emacs a few years back let me jettison a lot of accumulated cruft, but I still have a few glorious Elisp hacks lying around. My Emacs config file is actually 27 years old, and has just been lugged along from one machine to the next. 😅