It's fun to write small simple tools in the evening to come down. Here a tool to escape HTML as you can find it on every other HTML lerning website. It will replace the following characters with the right entities.
Character | Entity |
---|---|
& | & |
< | < |
> | > |
" | " |
' | ' |
/ | / |
Just paste your text into the textarea and push the button. Feel free to use it. This tool is JavaScript based and your input will not leave your client.
If you are interested in the code. Here is the necessary HTML and JavaScript code without styling elements and CSS (escaped with this tool).
<textarea id="not_escaped"></textarea>
<button onclick="escapeHtml();">escape</button>
<textarea id="escaped"></textarea>
<button onclick="unescapeHtml();">unescape</button>
<script>
var notEscaped = document.getElementById("not_escaped");
var escaped = document.getElementById("escaped");
var escapeMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
var unescapeMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
''': "'",
'/': "/"
};
function escapeHtml() {
escaped.value = String(notEscaped.value).replace(/[&<>"'\/]/g, function (s) {
return escapeMap[s];
});
}
function unescapeHtml() {
notEscaped.value = String(escaped.value).replace(/&|<|>|"|'|//g, function (s) {
return unescapeMap[s];
});
}
</script>