审查视图

packageA/wxParse/wxDiscode.js 6.9 KB
1  
朱振飞 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
// HTML 支持的数学符号
function strNumDiscode(str){
    str = str.replace(/∀/g, '∀');
    str = str.replace(/∂/g, '∂');
    str = str.replace(/&exists;/g, '∃');
    str = str.replace(/∅/g, '∅');
    str = str.replace(/∇/g, '∇');
    str = str.replace(/∈/g, '∈');
    str = str.replace(/∉/g, '∉');
    str = str.replace(/∋/g, '∋');
    str = str.replace(/∏/g, '∏');
    str = str.replace(/∑/g, '∑');
    str = str.replace(/−/g, '−');
    str = str.replace(/∗/g, '∗');
    str = str.replace(/√/g, '√');
    str = str.replace(/∝/g, '∝');
    str = str.replace(/∞/g, '∞');
    str = str.replace(/∠/g, '∠');
    str = str.replace(/∧/g, '∧');
    str = str.replace(/∨/g, '∨');
    str = str.replace(/∩/g, '∩');
    str = str.replace(/∩/g, '∪');
    str = str.replace(/∫/g, '∫');
    str = str.replace(/∴/g, '∴');
    str = str.replace(/∼/g, '∼');
    str = str.replace(/≅/g, '≅');
    str = str.replace(/≈/g, '≈');
    str = str.replace(/≠/g, '≠');
    str = str.replace(/≤/g, '≤');
    str = str.replace(/≥/g, '≥');
    str = str.replace(/⊂/g, '⊂');
    str = str.replace(/⊃/g, '⊃');
    str = str.replace(/⊄/g, '⊄');
    str = str.replace(/⊆/g, '⊆');
    str = str.replace(/⊇/g, '⊇');
    str = str.replace(/⊕/g, '⊕');
    str = str.replace(/⊗/g, '⊗');
    str = str.replace(/⊥/g, '⊥');
    str = str.replace(/⋅/g, '⋅');
    return str;
}

//HTML 支持的希腊字母
function strGreeceDiscode(str){
    str = str.replace(/Α/g, 'Α');
    str = str.replace(/Β/g, 'Β');
    str = str.replace(/Γ/g, 'Γ');
    str = str.replace(/Δ/g, 'Δ');
    str = str.replace(/Ε/g, 'Ε');
    str = str.replace(/Ζ/g, 'Ζ');
    str = str.replace(/Η/g, 'Η');
    str = str.replace(/Θ/g, 'Θ');
    str = str.replace(/Ι/g, 'Ι');
    str = str.replace(/Κ/g, 'Κ');
    str = str.replace(/Λ/g, 'Λ');
    str = str.replace(/Μ/g, 'Μ');
    str = str.replace(/Ν/g, 'Ν');
    str = str.replace(/Ξ/g, 'Ν');
    str = str.replace(/Ο/g, 'Ο');
    str = str.replace(/Π/g, 'Π');
    str = str.replace(/Ρ/g, 'Ρ');
    str = str.replace(/Σ/g, 'Σ');
    str = str.replace(/Τ/g, 'Τ');
    str = str.replace(/Υ/g, 'Υ');
    str = str.replace(/Φ/g, 'Φ');
    str = str.replace(/Χ/g, 'Χ');
    str = str.replace(/Ψ/g, 'Ψ');
    str = str.replace(/Ω/g, 'Ω');

    str = str.replace(/α/g, 'α');
    str = str.replace(/β/g, 'β');
    str = str.replace(/γ/g, 'γ');
    str = str.replace(/δ/g, 'δ');
    str = str.replace(/ε/g, 'ε');
    str = str.replace(/ζ/g, 'ζ');
    str = str.replace(/η/g, 'η');
    str = str.replace(/θ/g, 'θ');
    str = str.replace(/ι/g, 'ι');
    str = str.replace(/κ/g, 'κ');
    str = str.replace(/λ/g, 'λ');
    str = str.replace(/μ/g, 'μ');
    str = str.replace(/ν/g, 'ν');
    str = str.replace(/ξ/g, 'ξ');
    str = str.replace(/ο/g, 'ο');
    str = str.replace(/π/g, 'π');
    str = str.replace(/ρ/g, 'ρ');
    str = str.replace(/ς/g, 'ς');
    str = str.replace(/σ/g, 'σ');
    str = str.replace(/τ/g, 'τ');
    str = str.replace(/υ/g, 'υ');
    str = str.replace(/φ/g, 'φ');
    str = str.replace(/χ/g, 'χ');
    str = str.replace(/ψ/g, 'ψ');
    str = str.replace(/ω/g, 'ω');
    str = str.replace(/ϑ/g, 'ϑ');
    str = str.replace(/ϒ/g, 'ϒ');
    str = str.replace(/ϖ/g, 'ϖ');
    str = str.replace(/·/g, '·');
    return str;
}

// 

function strcharacterDiscode(str){
    // 加入常用解析
    str = str.replace(/ /g, ' ');
    str = str.replace(/"/g, "'");
    str = str.replace(/&/g, '&');
    // str = str.replace(/</g, '‹');
    // str = str.replace(/>/g, '›');

    str = str.replace(/&lt;/g, '<');
    str = str.replace(/&gt;/g, '>');
    str = str.replace(/&#8226;/g, '•');

    return str;
}

// HTML 支持的其他实体
function strOtherDiscode(str){
    str = str.replace(/&OElig;/g, 'Œ');
    str = str.replace(/&oelig;/g, 'œ');
    str = str.replace(/&Scaron;/g, 'Š');
    str = str.replace(/&scaron;/g, 'š');
    str = str.replace(/&Yuml;/g, 'Ÿ');
    str = str.replace(/&fnof;/g, 'ƒ');
    str = str.replace(/&circ;/g, 'ˆ');
    str = str.replace(/&tilde;/g, '˜');
    str = str.replace(/&ensp;/g, '');
    str = str.replace(/&emsp;/g, '');
    str = str.replace(/&thinsp;/g, '');
    str = str.replace(/&zwnj;/g, '');
    str = str.replace(/&zwj;/g, '');
    str = str.replace(/&lrm;/g, '');
    str = str.replace(/&rlm;/g, '');
    str = str.replace(/&ndash;/g, '–');
    str = str.replace(/&mdash;/g, '—');
    str = str.replace(/&lsquo;/g, '‘');
    str = str.replace(/&rsquo;/g, '’');
    str = str.replace(/&sbquo;/g, '‚');
    str = str.replace(/&ldquo;/g, '“');
    str = str.replace(/&rdquo;/g, '”');
    str = str.replace(/&bdquo;/g, '„');
    str = str.replace(/&dagger;/g, '†');
    str = str.replace(/&Dagger;/g, '‡');
    str = str.replace(/&bull;/g, '•');
    str = str.replace(/&hellip;/g, '…');
    str = str.replace(/&permil;/g, '‰');
    str = str.replace(/&prime;/g, '′');
    str = str.replace(/&Prime;/g, '″');
    str = str.replace(/&lsaquo;/g, '‹');
    str = str.replace(/&rsaquo;/g, '›');
    str = str.replace(/&oline;/g, '‾');
    str = str.replace(/&euro;/g, '€');
    str = str.replace(/&trade;/g, '™');

    str = str.replace(/&larr;/g, '←');
    str = str.replace(/&uarr;/g, '↑');
    str = str.replace(/&rarr;/g, '→');
    str = str.replace(/&darr;/g, '↓');
    str = str.replace(/&harr;/g, '↔');
    str = str.replace(/&crarr;/g, '↵');
    str = str.replace(/&lceil;/g, '⌈');
    str = str.replace(/&rceil;/g, '⌉');

    str = str.replace(/&lfloor;/g, '⌊');
    str = str.replace(/&rfloor;/g, '⌋');
    str = str.replace(/&loz;/g, '◊');
    str = str.replace(/&spades;/g, '♠');
    str = str.replace(/&clubs;/g, '♣');
    str = str.replace(/&hearts;/g, '♥');

    str = str.replace(/&diams;/g, '♦');
    str = str.replace(/&#39;/g, '\'');
    return str;
}

function strMoreDiscode(str){
    str = str.replace(/\r\n/g,"");  
    str = str.replace(/\n/g,"");

    str = str.replace(/code/g,"wxxxcode-style");
    return str;
}

function strDiscode(str){
    str = strNumDiscode(str);
    str = strGreeceDiscode(str);
    str = strcharacterDiscode(str);
    str = strOtherDiscode(str);
    str = strMoreDiscode(str);
    return str;
}
function urlToHttpUrl(url,rep){
    
    var patt1 = new RegExp("^//");
    var result = patt1.test(url);
    if(result){
        url = rep+":"+url;
    }
    return  url;
}

module.exports = {
    strDiscode:strDiscode,
    urlToHttpUrl:urlToHttpUrl
}