Created
January 20, 2021 19:24
-
-
Save bobdobbalina/844262d1bd8ae6a2ba7946abd889fe38 to your computer and use it in GitHub Desktop.
Javascript: Unescape HTML tags
This file contains hidden or 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
const unescapeHTML = str => | |
str.replace( | |
/&|<|>|'|"/g, | |
tag => | |
({ | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
''': "'", | |
'"': '"' | |
}[tag] || tag) | |
); | |
data["unescapeHTML"] = unescapeHTML('<a href="#">Me & you</a>'); // <a href="#">Me & you</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment