add HTML entity de- and encoding

This commit is contained in:
Manuel Friedli 2015-03-26 22:06:54 +01:00
parent e6de88ef31
commit feb7939488

View file

@ -92,6 +92,41 @@
}; };
} }
} }
},
{
"id": "encodehtmlentities",
"name": "Encode HTML entities",
"convert": function (input) {
return {
"status": "OK",
"content": input
.replace(/\&/g, "&")
.replace(/\</g, "&lt;")
.replace(/\>/g, "&gt;")
.replace(/\"/g, "&quot;")
};
}
},
{
"id": "decodehtmlentities",
"name": "Decode HTML entities",
"convert": function (input) {
try {
return {
"status": "OK",
"content": input
.replace(/\&quot\;/g, "\"")
.replace(/\&gt\;/g, ">")
.replace(/\&lt\;/g, "<")
.replace(/\&amp\;/g, "&")
};
} catch (exception) {
return {
"status": "ERROR",
"content": "Invalid HTML entity string."
};
}
}
} }
]; ];
@ -151,7 +186,7 @@
} }
if (appendNewOutput) { if (appendNewOutput) {
if (output !== "") { if (output !== "") {
$output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output)); $output = $(template.replace(/\{index\}/g, "" + outputIndex).replace(/\{content\}/g, output.replace(/\&/g, "&amp;")));
if (status === "ERROR") { if (status === "ERROR") {
$output.find("textarea").addClass("error"); $output.find("textarea").addClass("error");
} }