Created
March 7, 2023 00:14
-
-
Save moroz/1dc7789445e39d369e40a5446d17e267 to your computer and use it in GitHub Desktop.
Escape non-alphanumerics in HTML strings
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
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