You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

209 lines
9.4 KiB

This file contains unexpected Bidirectional Unicode characters!

This file contains unexpected Bidirectional Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// HTML 支持的数学符号
function strNumDiscode(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, '⋅');
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(/&#12288;|&#x3000;/g, '<span class=\'spaceshow\'> </span>');
// str = str.replace(/&emsp;|&#8195;|&#x2003;/g, '&emsp;');
// str = str.replace(/&quot;|&#34;|&#x22;/g, "\"");
// str = str.replace(/&apos;|&#39;|&#x27;/g, "&apos;");
// str = str.replace(/&acute;|&#180;|&#xB4;/g, "´");
// str = str.replace(/&times;|&#215;|&#xD7;/g, "×");
// str = str.replace(/&divide;|&#247;|&#xF7;/g, "÷");
// str = str.replace(/&amp;|&#38;|&#x26;/g, '&amp;');
// str = str.replace(/&lt;|&#60;|&#x3c;/g, '&lt;');
// str = str.replace(/&gt;|&#62;|&#x3e;/g, '&gt;');
str = str.replace(/&nbsp;|&#32;|&#x20;/g, "<span class='spaceshow'> </span>");
str = str.replace(/&ensp;|&#8194;|&#x2002;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&#12288;|&#x3000;/g, '<span class=\'spaceshow\'> </span>');
str = str.replace(/&emsp;|&#8195;|&#x2003;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&quot;|&#34;|&#x22;/g, "\"");
str = str.replace(/&quot;|&#39;|&#x27;/g, "'");
str = str.replace(/&acute;|&#180;|&#xB4;/g, "´");
str = str.replace(/&times;|&#215;|&#xD7;/g, "×");
str = str.replace(/&divide;|&#247;|&#xF7;/g, "÷");
str = str.replace(/&amp;|&#38;|&#x26;/g, '&');
str = str.replace(/&lt;|&#60;|&#x3c;/g, '<');
str = str.replace(/&gt;|&#62;|&#x3e;/g, '>');
return str;
}
// HTML 支持的其他实体
function strOtherDiscode(str) {
str = str.replace(/&OElig;|&#338;|&#x152;/g, 'Œ');
str = str.replace(/&oelig;|&#339;|&#x153;/g, 'œ');
str = str.replace(/&Scaron;|&#352;|&#x160;/g, 'Š');
str = str.replace(/&scaron;|&#353;|&#x161;/g, 'š');
str = str.replace(/&Yuml;|&#376;|&#x178;/g, 'Ÿ');
str = str.replace(/&fnof;|&#402;|&#x192;/g, 'ƒ');
str = str.replace(/&circ;|&#710;|&#x2c6;/g, 'ˆ');
str = str.replace(/&tilde;|&#732;|&#x2dc;/g, '˜');
str = str.replace(/&thinsp;|$#8201;|&#x2009;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&zwnj;|&#8204;|&#x200C;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&zwj;|$#8205;|&#x200D;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&lrm;|$#8206;|&#x200E;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&rlm;|&#8207;|&#x200F;/g, '<span class=\'spaceshow\'></span>');
str = str.replace(/&ndash;|&#8211;|&#x2013;/g, '–');
str = str.replace(/&mdash;|&#8212;|&#x2014;/g, '—');
str = str.replace(/&lsquo;|&#8216;|&#x2018;/g, '‘');
str = str.replace(/&rsquo;|&#8217;|&#x2019;/g, '’');
str = str.replace(/&sbquo;|&#8218;|&#x201a;/g, '‚');
str = str.replace(/&ldquo;|&#8220;|&#x201c;/g, '“');
str = str.replace(/&rdquo;|&#8221;|&#x201d;/g, '”');
str = str.replace(/&bdquo;|&#8222;|&#x201e;/g, '„');
str = str.replace(/&dagger;|&#8224;|&#x2020;/g, '†');
str = str.replace(/&Dagger;|&#8225;|&#x2021;/g, '‡');
str = str.replace(/&bull;|&#8226;|&#x2022;/g, '•');
str = str.replace(/&hellip;|&#8230;|&#x2026;/g, '…');
str = str.replace(/&permil;|&#8240;|&#x2030;/g, '‰');
str = str.replace(/&prime;|&#8242;|&#x2032;/g, '′');
str = str.replace(/&Prime;|&#8243;|&#x2033;/g, '″');
str = str.replace(/&lsaquo;|&#8249;|&#x2039;/g, '‹');
str = str.replace(/&rsaquo;|&#8250;|&#x203a;/g, '›');
str = str.replace(/&oline;|&#8254;|&#x203e;/g, '‾');
str = str.replace(/&euro;|&#8364;|&#x20ac;/g, '€');
str = str.replace(/&trade;|&#8482;|&#x2122;/g, '™');
str = str.replace(/&larr;|&#8592;|&#x2190;/g, '←');
str = str.replace(/&uarr;|&#8593;|&#x2191;/g, '↑');
str = str.replace(/&rarr;|&#8594;|&#x2192;/g, '→');
str = str.replace(/&darr;|&#8595;|&#x2193;/g, '↓');
str = str.replace(/&harr;|&#8596;|&#x2194;/g, '↔');
str = str.replace(/&crarr;|&#8629;|&#x21b5;/g, '↵');
str = str.replace(/&lceil;|&#8968;|&#x2308;/g, '⌈');
str = str.replace(/&rceil;|&#8969;|&#x2309;/g, '⌉');
str = str.replace(/&lfloor;|&#8970;|&#x230a;/g, '⌊');
str = str.replace(/&rfloor;|&#8971;|&#x230b;/g, '⌋');
str = str.replace(/&loz;|&#9674;|&#x25ca;/g, '◊');
str = str.replace(/&spades;|&#9824;|&#x2660;/g, '♠');
str = str.replace(/&clubs;|&#9827;|&#x2663;/g, '♣');
str = str.replace(/&hearts;|&#9829;|&#x2665;/g, '♥');
str = str.replace(/&diams;|&#9830;|&#x2666;/g, '♦');
return str;
}
function strDiscode(str) {
str = strNumDiscode(str);
str = strGreeceDiscode(str);
str = strcharacterDiscode(str);
str = strOtherDiscode(str);
return str;
}
function urlToHttpUrl(url, domain) {
if (/^\/\//.test(url)) {
return `https:${url}`;
} else if (/^\//.test(url)) {
return `https://${domain}${url}`;
}
return url;
}
export default {
strDiscode,
urlToHttpUrl,
};