User:AoV2/unicodify.js

function unicodify(txt) { txt = txt.replace(/&mdash;/gi, '—').replace(/–/gi, '–'); if(txt.match(/&[a-z][a-z]+[0-9]*;/i)) { txt = txt .replace(/([^\.])(?:...|&hellip;)([^\.])/gi, '$1…$2') .replace(/&plus;/gi, '+').replace(/&plusmn;/gi, "±").replace(/&minus;/gi, "−").replace(/&times;/gi, "×") .replace(/&divide;/gi, "÷").replace(/&ne;/gi, "≠").replace(/&asymp;/gi, "≈").replace(/&le;/gi, "≤") .replace(/&ge;/gi, "≥").replace(/&quot;/gi, "\"").replace(/&apos;/gi, "'").replace(/&iexcl;/gi, "¡")		.replace(/&cent;/gi, "¢").replace(/&pound;/gi, "£").replace(/&curren;/gi, "¤").replace(/&yen;/gi, "¥")		.replace(/&brvbar;/gi, "¦").replace(/&sect;/gi, "§").replace(/&uml;/gi, "¨").replace(/&copy;/gi, "©")		.replace(/&ordf;/gi, "ª").replace(/&laquo;/gi, "«").replace(/&not;/gi, "¬").replace(/&reg;/gi, "®")		.replace(/&macr;/gi, "¯").replace(/&deg;/gi, "°").replace(/&sup2;/gi, "²").replace(/&sup3;/gi, "³")		.replace(/&acute;/gi, "´").replace(/&micro;/gi, "µ").replace(/&para;/gi, "¶").replace(/&middot;/gi, "·")		.replace(/&cedil;/gi, "¸").replace(/&sup1;/gi, "¹").replace(/&ordm;/gi, "º").replace(/&raquo;/gi, "»")		.replace(/&frac14;/gi, "¼").replace(/&frac12;/gi, "½").replace(/&frac34;/gi, "¾").replace(/&iquest;/gi, "¿")		.replace(/&circ;/gi, "ˆ").replace(/&tilde;/gi, "˜").replace(/&lsquo;/gi, "‘").replace(/&rsquo;/gi, "’") .replace(/&sbquo;/gi, "‚").replace(/&ldquo;/gi, "“").replace(/&rdquo;/gi, "”").replace(/&bdquo;/gi, "„") .replace(/&bull;/gi, "•").replace(/&permil;/gi, "‰").replace(/&lsaquo;/gi, "‹").replace(/&rsaquo;/gi, "›") .replace(/&oline;/gi, "‾").replace(/&frasl;/gi, "⁄").replace(/&euro;/gi, "€").replace(/&image;/gi, "ℑ") .replace(/&weierp;/gi, "℘").replace(/&real;/gi, "ℜ").replace(/&trade;/gi, "™").replace(/&alefsym;/gi, "ℵ") .replace(/&crarr;/gi, "↵").replace(/&forall;/gi, "∀").replace(/&part;/gi, "∂").replace(/&exist;/gi, "∃") .replace(/&empty;/gi, "∅").replace(/&nabla;/gi, "∇").replace(/&isin;/gi, "∈").replace(/&notin;/gi, "∉") .replace(/&ni;/gi, "∋").replace(/&prod;/gi, "∏").replace(/&sum;/gi, "∑").replace(/&lowast;/gi, "∗") .replace(/&radic;/gi, "√").replace(/&prop;/gi, "∝").replace(/&infin;/gi, "∞").replace(/&ang;/gi, "∠") .replace(/&and;/gi, "∧").replace(/&or;/gi, "∨").replace(/&cap;/gi, "∩").replace(/&cup;/gi, "∪") .replace(/&int;/gi, "∫").replace(/&there4;/gi, "∴").replace(/&sim;/gi, "∼").replace(/&cong;/gi, "≅") .replace(/&sub;/gi, "⊂").replace(/&sup;/gi, "⊃").replace(/&nsub;/gi, "⊄").replace(/&sube;/gi, "⊆") .replace(/&supe;/gi, "⊇").replace(/&oplus;/gi, "⊕").replace(/&otimes;/gi, "⊗").replace(/&perp;/gi, "⊥") .replace(/&sdot;/gi, "⋅").replace(/&lceil;/gi, "⌈").replace(/&rceil;/gi, "⌉").replace(/&lfloor;/gi, "⌊") .replace(/&rfloor;/gi, "⌋").replace(/&lang;/gi, "〈").replace(/&rang;/gi, "〉").replace(/&loz;/gi, "◊") .replace(/&spades;/gi, "♠").replace(/&clubs;/gi, "♣").replace(/&hearts;/gi, "♥").replace(/&diams;/gi, "♦") ;}	if(txt.match(/&[A-Z][a-z]+;/)) { txt = txt .replace(/&Alpha;/g, "Α").replace(/&Beta;/g, "Β").replace(/&Gamma;/g, "Γ").replace(/&Delta;/g, "Δ") .replace(/&Epsilon;/g, "Ε").replace(/&Zeta;/g, "Ζ").replace(/&Eta;/g, "Η").replace(/&Theta;/g, "Θ") .replace(/&Iota;/g, "Ι").replace(/&Kappa;/g, "Κ").replace(/&Lambda;/g, "Λ").replace(/&Mu;/g, "Μ") .replace(/&Nu;/g, "Ν").replace(/&Xi;/g, "Ξ").replace(/&Omicron;/g, "Ο").replace(/&Pi;/g, "Π") .replace(/&Rho;/g, "Ρ").replace(/&Sigma;/g, "Σ").replace(/&Tau;/g, "Τ").replace(/&Upsilon;/g, "Υ") .replace(/&Phi;/g, "Φ").replace(/&Chi;/g, "Χ").replace(/&Psi;/g, "Ψ").replace(/&Omega;/g, "Ω") .replace(/&Agrave;/g, "À").replace(/&Aacute;/g, "Á").replace(/&Acirc;/g, "Â").replace(/&Atilde;/g, "Ã") .replace(/&Auml;/g, "Ä").replace(/&Aring;/g, "Å").replace(/&AElig;/g, "Æ").replace(/&Ccedil;/g, "Ç") .replace(/&Egrave;/g, "È").replace(/&Eacute;/g, "É").replace(/&Ecirc;/g, "Ê").replace(/&Euml;/g, "Ë") .replace(/&Igrave;/g, "Ì").replace(/&Iacute;/g, "Í").replace(/&Icirc;/g, "Î").replace(/&Iuml;/g, "Ï") .replace(/&Ntilde;/g, "Ñ").replace(/&Ograve;/g, "Ò").replace(/&Oacute;/g, "Ó").replace(/&Ocirc;/g, "Ô") .replace(/&Otilde;/g, "Õ").replace(/&Ouml;/g, "Ö").replace(/&Oslash;/g, "Ø").replace(/&Ugrave;/g, "Ù") .replace(/&Uacute;/g, "Ú").replace(/&Ucirc;/g, "Û").replace(/&Uuml;/g, "Ü").replace(/&Yacute;/g, "Ý") .replace(/&Scaron;/g, "Š").replace(/&Yuml;/g, "Ÿ") .replace(/&Dagger;/g, "‡").replace(/&Prime;/g, "″") ;}	if(str.match(/&[a-z][a-z]+;/)) { txt = txt .replace(/&alpha;/g, "α").replace(/&beta;/g, "β").replace(/&gamma;/g, "γ").replace(/&delta;/g, "δ") .replace(/&epsilon;/g, "ε").replace(/&zeta;/g, "ζ").replace(/&eta;/g, "η").replace(/&theta;/g, "θ") .replace(/&iota;/g, "ι").replace(/&kappa;/g, "κ").replace(/&lambda;/g, "λ").replace(/&mu;/g, "μ") .replace(/&nu;/g, "ν").replace(/&xi;/g, "ξ").replace(/&omicron;/g, "ο").replace(/&pi;/g, "π") .replace(/&rho;/g, "ρ").replace(/&sigmaf;/g, "ς").replace(/&sigma;/g, "σ").replace(/&tau;/g, "τ") .replace(/&upsilon;/g, "υ").replace(/&phi;/g, "φ").replace(/&chi;/g, "χ").replace(/&psi;/g, "ψ") .replace(/&omega;/g, "ω").replace(/&thetasym;/g, "ϑ").replace(/&upsih;/g, "ϒ").replace(/&piv;/g, "ϖ") .replace(/&szlig;/g, "ß").replace(/&agrave;/g, "à").replace(/&aacute;/g, "á").replace(/&acirc;/g, "â") .replace(/&atilde;/g, "ã").replace(/&auml;/g, "ä").replace(/&aring;/g, "å").replace(/&aelig;/g, "æ") .replace(/&ccedil;/g, "ç").replace(/&egrave;/g, "è").replace(/&eacute;/g, "é").replace(/&ecirc;/g, "ê") .replace(/&euml;/g, "ë").replace(/&igrave;/g, "ì").replace(/&iacute;/g, "í").replace(/&icirc;/g, "î") .replace(/&iuml;/g, "ï").replace(/&eth;/g, "ð").replace(/&ntilde;/g, "ñ").replace(/&ograve;/g, "ò") .replace(/&oacute;/g, "ó").replace(/&ocirc;/g, "ô").replace(/&otilde;/g, "õ").replace(/&ouml;/g, "ö") .replace(/&oslash;/g, "ø").replace(/&ugrave;/g, "ù").replace(/&uacute;/g, "ú").replace(/&ucirc;/g, "û") .replace(/&uuml;/g, "ü").replace(/&yacute;/g, "ý").replace(/&thorn;/g, "þ").replace(/&yuml;/g, "ÿ") .replace(/&oelig;/g, "œ").replace(/&scaron;/g, "š").replace(/&fnof;/g, "ƒ") .replace(/&dagger;/g, "†").replace(/&prime;/g, "′") ;}	txt = txt .replace(/&larr;/g, "←").replace(/&rarr;/g, "→").replace(/&uarr;/g, "↑").replace(/&darr;/g, "↓").replace(/&lArr;/g, "⇐") .replace(/&rArr;/g, "⇒").replace(/&uArr;/g, "⇑").replace(/&dArr;/g, "⇓").replace(/&harr;/g, "↔").replace(/&hArr;/g, "⇔") .replace(/&ETH;/g, "Ð").replace(/&THORN;/g, "Þ").replace(/&OElig;/g, "Œ") ;}	var dont_replace = "|!{}[]=<>"; function repl(ent, base) { var n = parseInt(ent.replace(/[\&\#\;x]/g, ''), base); var c = (n > 0xFFFF) ? String.fromCharCode(0xD800 + ((n - 0x10000) >> 10), 0xDC00 + ((n - 0x10000) & 0x3FF)) : String.fromCharCode(n); if(!dont_replace.match(c)) txt = txt.replace(ent, c, "gi"); }	if(m = str.match(/\&\#(\d+)\;/g)) for(i = 0; i < m.length; i++) repl(m[i], 10); if(m = str.match(/\&\#x([\da-f]+)\;/gi)) for(i = 0; i < m.length; i++) repl(m[i], 16); var fail = ""; return txt .replace(/\u0080/g, "€").replace(/\u0081/g,fail).replace(/\u0082/g, "‚").replace(/\u0083/g, "ƒ") .replace(/\u0084/g, "„").replace(/\u0085/g, "…").replace(/\u0086/g, "†").replace(/\u0087/g, "‡") .replace(/\u0088/g, "ˆ").replace(/\u0089/g, "‰").replace(/\u008a/g, "Š").replace(/\u008b/g, "‹") .replace(/\u008c/g, "Œ").replace(/\u008d/g,fail).replace(/\u008e/g, "Ž").replace(/\u008f/g,fail) .replace(/\u0090/g,fail).replace(/\u0091/g, "‘").replace(/\u0092/g, "’").replace(/\u0093/g, "“") .replace(/\u0094/g, "”").replace(/\u0095/g, "•").replace(/\u0096/g, "–").replace(/\u0097/g, "—") .replace(/\u0098/g, "˜").replace(/\u0099/g, "™").replace(/\u009a/g, "š").replace(/\u009b/g, "›") .replace(/\u009c/g, "œ").replace(/\u009d/g,fail).replace(/\u009e/g, "ž").replace(/\u009f/g, "Ÿ") ;}