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
1 changed files with 43 additions and 8 deletions

View File

@ -3,7 +3,7 @@
{
"id": "CHOOSE",
"name": "Please choose your conversion ...",
"convert": function(input) {
"convert": function (input) {
return {
"status": "OK",
"content": ""
@ -13,7 +13,7 @@
{
"id": "base64encode",
"name": "Base64 encode",
"convert": function(input) {
"convert": function (input) {
return {
"status": "OK",
"content": btoa(input)
@ -23,7 +23,7 @@
{
"id": "base64decode",
"name": "Base64 decode",
"convert": function(input) {
"convert": function (input) {
try {
return {
"status": "OK",
@ -40,7 +40,7 @@
{
"id": "encodeuri",
"name": "Encode URI",
"convert": function(input) {
"convert": function (input) {
return {
"status": "OK",
"content": encodeURI(input).replace(/%5B/g, '[').replace(/%5D/g, ']')
@ -50,7 +50,7 @@
{
"id": "decodeuri",
"name": "Decode URI",
"convert": function(input) {
"convert": function (input) {
try {
return {
"status": "OK",
@ -67,7 +67,7 @@
{
"id": "encodeuricomponent",
"name": "Encode URI component",
"convert": function(input) {
"convert": function (input) {
return {
"status": "OK",
"content": encodeURIComponent(input).replace(/[!'()*]/g, function(c) {
@ -79,7 +79,7 @@
{
"id": "decodeuricomponent",
"name": "Decode URI component",
"convert": function(input) {
"convert": function (input) {
try {
return {
"status": "OK",
@ -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 (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") {
$output.find("textarea").addClass("error");
}