Skip to content

Instantly share code, notes, and snippets.

@moroz
Created March 7, 2023 00:14
Show Gist options
  • Save moroz/1dc7789445e39d369e40a5446d17e267 to your computer and use it in GitHub Desktop.
Save moroz/1dc7789445e39d369e40a5446d17e267 to your computer and use it in GitHub Desktop.
Escape non-alphanumerics in HTML strings
escape = fn str ->
str
|> Base.encode16()
|> String.replace_prefix("", "&#x")
|> String.replace_suffix("", ";")
end
String.replace(string, ~r/\W/, escape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment