Houdini's publicist#
A fork of houdini that adds a function specifically for escaping attributes but only adds quotes when the string isn't alphanumeric or one of -_./:. Why would you want this? Well to have a slightly smaller html file size. Probably not worth it! 🤷
This isn't added to Hex, so you'll have to add it as a git dependency in your gleam.toml:
houdinis_publicist = { git = "https://github.com/bentomas/houdinis_publicist.git", ref = "595cdc46" }
It automatically adds the quotes for you if they are necessary:
houdinis_publicist.escape_attribute("abcd")
// => "abcd"
houdinis_publicist.escape_attribute("ab_cd")
// => "ab_cd"
houdinis_publicist.escape_attribute("ab cd")
// => "\"ab cd\""
houdinis_publicist.escape_attribute("a\"")
// => "\"a"\""
I've only written the function in pure Gleam, and unlike the original houdini haven't written an optimized version for Javascript. So it probably isn't very fast there.