+
diff --git a/js/scripts.js b/js/scripts.js
index 873de35..54c90c0 100755
--- a/js/scripts.js
+++ b/js/scripts.js
@@ -6,6 +6,8 @@ $(document).ready(function(){
$('#btnUrlDecode').click(function (){urlDecode();});
$('#btnJsonFormat').click(function (){jsonFormat();});
$('#btnXmlFormat').click(function (){xmlFormat();});
+ $('#btnHtmlEncode').click(function (){htmlEncode();});
+ $('#btnHtmlDecode').click(function (){htmlDecode();});
});
function base64encode(){
@@ -112,6 +114,26 @@ function xmlFormat(sourceXml){
}
};
+function htmlEncode(){
+ var text = get('textAreaHtmlInput').value;
+ var encoded = text
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+ get('preHtmlOutputCode').innerText = encoded;
+}
+
+function htmlDecode(){
+ var text = get('textAreaHtmlInput').value;
+ // Uses the browser's HTML parser for decoding entities, which may handle certain edge cases differently than manual replacements.
+ var parser = new DOMParser();
+ var dom = parser.parseFromString(text, 'text/html');
+ var decoded = dom.documentElement.textContent;
+ get('preHtmlOutputCode').innerText = decoded;
+}
+
function get(id){
return document.getElementById(id);
}