Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

210 lignes
9.4 KiB

  1. // HTML 支持的数学符号
  2. function strNumDiscode(str) {
  3. str = str.replace(/∀|∀|∀/g, '∀');
  4. str = str.replace(/∂|∂|∂/g, '∂');
  5. str = str.replace(/∃|∃|∃/g, '∃');
  6. str = str.replace(/∅|∅|∅/g, '∅');
  7. str = str.replace(/∇|∇|∇/g, '∇');
  8. str = str.replace(/∈|∈|∈/g, '∈');
  9. str = str.replace(/∉|∉|∉/g, '∉');
  10. str = str.replace(/∋|∋|∋/g, '∋');
  11. str = str.replace(/∏|∏|∏/g, '∏');
  12. str = str.replace(/∑|∑|∑/g, '∑');
  13. str = str.replace(/−|−|−/g, '−');
  14. str = str.replace(/∗|∗|∗/g, '∗');
  15. str = str.replace(/√|√|√/g, '√');
  16. str = str.replace(/∝|∝|∝/g, '∝');
  17. str = str.replace(/∞|∞|∞/g, '∞');
  18. str = str.replace(/∠|∠|∠/g, '∠');
  19. str = str.replace(/∧|∧|∧/g, '∧');
  20. str = str.replace(/∨|∨|∨/g, '∨');
  21. str = str.replace(/∩|∩|∩/g, '∩');
  22. str = str.replace(/∪|∪|∪/g, '∪');
  23. str = str.replace(/∫|∫|∫/g, '∫');
  24. str = str.replace(/∴|∴|∴/g, '∴');
  25. str = str.replace(/∼|∼|∼/g, '∼');
  26. str = str.replace(/≅|≅|≅/g, '≅');
  27. str = str.replace(/≈|≈|≈/g, '≈');
  28. str = str.replace(/≠|≠|≠/g, '≠');
  29. str = str.replace(/≤|≤|≤/g, '≤');
  30. str = str.replace(/≥|≥|≥/g, '≥');
  31. str = str.replace(/⊂|⊂|⊂/g, '⊂');
  32. str = str.replace(/⊃|⊃|⊃/g, '⊃');
  33. str = str.replace(/⊄|⊄|⊄/g, '⊄');
  34. str = str.replace(/⊆|⊆|⊆/g, '⊆');
  35. str = str.replace(/⊇|⊇|⊇/g, '⊇');
  36. str = str.replace(/⊕|⊕|⊕/g, '⊕');
  37. str = str.replace(/⊗|⊗|⊗/g, '⊗');
  38. str = str.replace(/⊥|⊥|⊥/g, '⊥');
  39. str = str.replace(/⋅|⋅|⋅/g, '⋅');
  40. return str;
  41. }
  42. // HTML 支持的希腊字母
  43. function strGreeceDiscode(str) {
  44. str = str.replace(/Α|Α|Α/g, 'Α');
  45. str = str.replace(/Β|Β|Β/g, 'Β');
  46. str = str.replace(/Γ|Γ|Γ/g, 'Γ');
  47. str = str.replace(/Δ|Δ|Δ/g, 'Δ');
  48. str = str.replace(/Ε|Ε|Ε/g, 'Ε');
  49. str = str.replace(/Ζ|Ζ|Ζ/g, 'Ζ');
  50. str = str.replace(/Η|Η|Η/g, 'Η');
  51. str = str.replace(/Θ|Θ|Θ/g, 'Θ');
  52. str = str.replace(/Ι|Ι|Ι/g, 'Ι');
  53. str = str.replace(/Κ|Κ|Κ/g, 'Κ');
  54. str = str.replace(/Λ|Λ|Λ/g, 'Λ');
  55. str = str.replace(/Μ|Μ|Μ/g, 'Μ');
  56. str = str.replace(/Ν|Ν|Ν/g, 'Ν');
  57. str = str.replace(/Ξ|Ν|Ν/g, 'Ν');
  58. str = str.replace(/Ο|Ο|Ο/g, 'Ο');
  59. str = str.replace(/Π|Π|Π/g, 'Π');
  60. str = str.replace(/Ρ|Ρ|Ρ/g, 'Ρ');
  61. str = str.replace(/Σ|Σ|Σ/g, 'Σ');
  62. str = str.replace(/Τ|Τ|Τ/g, 'Τ');
  63. str = str.replace(/Υ|Υ|Υ/g, 'Υ');
  64. str = str.replace(/Φ|Φ|Φ/g, 'Φ');
  65. str = str.replace(/Χ|Χ|Χ/g, 'Χ');
  66. str = str.replace(/Ψ|Ψ|Ψ/g, 'Ψ');
  67. str = str.replace(/Ω|Ω|Ω/g, 'Ω');
  68. str = str.replace(/α|α|α/g, 'α');
  69. str = str.replace(/β|β|β/g, 'β');
  70. str = str.replace(/γ|γ|γ/g, 'γ');
  71. str = str.replace(/δ|δ|δ/g, 'δ');
  72. str = str.replace(/ε|ε|ε/g, 'ε');
  73. str = str.replace(/ζ|ζ|ζ/g, 'ζ');
  74. str = str.replace(/η|η|η/g, 'η');
  75. str = str.replace(/θ|θ|θ/g, 'θ');
  76. str = str.replace(/ι|ι|ι/g, 'ι');
  77. str = str.replace(/κ|κ|κ/g, 'κ');
  78. str = str.replace(/λ|λ|λ/g, 'λ');
  79. str = str.replace(/μ|μ|μ/g, 'μ');
  80. str = str.replace(/ν|ν|ν/g, 'ν');
  81. str = str.replace(/ξ|ξ|ξ/g, 'ξ');
  82. str = str.replace(/ο|ο|ο/g, 'ο');
  83. str = str.replace(/π|π|π/g, 'π');
  84. str = str.replace(/ρ|ρ|ρ/g, 'ρ');
  85. str = str.replace(/ς|ς|ς/g, 'ς');
  86. str = str.replace(/σ|σ|σ/g, 'σ');
  87. str = str.replace(/τ|τ|τ/g, 'τ');
  88. str = str.replace(/υ|υ|υ/g, 'υ');
  89. str = str.replace(/φ|φ|φ/g, 'φ');
  90. str = str.replace(/χ|χ|χ/g, 'χ');
  91. str = str.replace(/ψ|ψ|ψ/g, 'ψ');
  92. str = str.replace(/ω|ω|ω/g, 'ω');
  93. str = str.replace(/ϑ|ϑ|ϑ/g, 'ϑ');
  94. str = str.replace(/ϒ|ϒ|ϒ/g, 'ϒ');
  95. str = str.replace(/ϖ|ϖ|ϖ/g, 'ϖ');
  96. str = str.replace(/·|·|·/g, '·');
  97. return str;
  98. }
  99. function strcharacterDiscode(str) {
  100. // 加入常用解析
  101. // str = str.replace(/ | | /g, " ");
  102. // str = str.replace(/ | | /g, ' ');
  103. // str = str.replace(/&#12288;|&#x3000;/g, '<span class=\'spaceshow\'> </span>');
  104. // str = str.replace(/&emsp;|&#8195;|&#x2003;/g, '&emsp;');
  105. // str = str.replace(/&quot;|&#34;|&#x22;/g, "\"");
  106. // str = str.replace(/&apos;|&#39;|&#x27;/g, "&apos;");
  107. // str = str.replace(/&acute;|&#180;|&#xB4;/g, "´");
  108. // str = str.replace(/&times;|&#215;|&#xD7;/g, "×");
  109. // str = str.replace(/&divide;|&#247;|&#xF7;/g, "÷");
  110. // str = str.replace(/&amp;|&#38;|&#x26;/g, '&amp;');
  111. // str = str.replace(/&lt;|&#60;|&#x3c;/g, '&lt;');
  112. // str = str.replace(/&gt;|&#62;|&#x3e;/g, '&gt;');
  113. str = str.replace(/&nbsp;|&#32;|&#x20;/g, "<span class='spaceshow'> </span>");
  114. str = str.replace(/&ensp;|&#8194;|&#x2002;/g, '<span class=\'spaceshow\'> </span>');
  115. str = str.replace(/&#12288;|&#x3000;/g, '<span class=\'spaceshow\'> </span>');
  116. str = str.replace(/&emsp;|&#8195;|&#x2003;/g, '<span class=\'spaceshow\'> </span>');
  117. str = str.replace(/&quot;|&#34;|&#x22;/g, "\"");
  118. str = str.replace(/&quot;|&#39;|&#x27;/g, "'");
  119. str = str.replace(/&acute;|&#180;|&#xB4;/g, "´");
  120. str = str.replace(/&times;|&#215;|&#xD7;/g, "×");
  121. str = str.replace(/&divide;|&#247;|&#xF7;/g, "÷");
  122. str = str.replace(/&amp;|&#38;|&#x26;/g, '&');
  123. str = str.replace(/&lt;|&#60;|&#x3c;/g, '<');
  124. str = str.replace(/&gt;|&#62;|&#x3e;/g, '>');
  125. return str;
  126. }
  127. // HTML 支持的其他实体
  128. function strOtherDiscode(str) {
  129. str = str.replace(/&OElig;|&#338;|&#x152;/g, 'Œ');
  130. str = str.replace(/&oelig;|&#339;|&#x153;/g, 'œ');
  131. str = str.replace(/&Scaron;|&#352;|&#x160;/g, 'Š');
  132. str = str.replace(/&scaron;|&#353;|&#x161;/g, 'š');
  133. str = str.replace(/&Yuml;|&#376;|&#x178;/g, 'Ÿ');
  134. str = str.replace(/&fnof;|&#402;|&#x192;/g, 'ƒ');
  135. str = str.replace(/&circ;|&#710;|&#x2c6;/g, 'ˆ');
  136. str = str.replace(/&tilde;|&#732;|&#x2dc;/g, '˜');
  137. str = str.replace(/&thinsp;|$#8201;|&#x2009;/g, '<span class=\'spaceshow\'> </span>');
  138. str = str.replace(/&zwnj;|&#8204;|&#x200C;/g, '<span class=\'spaceshow\'>‌</span>');
  139. str = str.replace(/&zwj;|$#8205;|&#x200D;/g, '<span class=\'spaceshow\'>‍</span>');
  140. str = str.replace(/&lrm;|$#8206;|&#x200E;/g, '<span class=\'spaceshow\'>‎</span>');
  141. str = str.replace(/&rlm;|&#8207;|&#x200F;/g, '<span class=\'spaceshow\'>‏</span>');
  142. str = str.replace(/&ndash;|&#8211;|&#x2013;/g, '–');
  143. str = str.replace(/&mdash;|&#8212;|&#x2014;/g, '—');
  144. str = str.replace(/&lsquo;|&#8216;|&#x2018;/g, '‘');
  145. str = str.replace(/&rsquo;|&#8217;|&#x2019;/g, '’');
  146. str = str.replace(/&sbquo;|&#8218;|&#x201a;/g, '‚');
  147. str = str.replace(/&ldquo;|&#8220;|&#x201c;/g, '“');
  148. str = str.replace(/&rdquo;|&#8221;|&#x201d;/g, '”');
  149. str = str.replace(/&bdquo;|&#8222;|&#x201e;/g, '„');
  150. str = str.replace(/&dagger;|&#8224;|&#x2020;/g, '†');
  151. str = str.replace(/&Dagger;|&#8225;|&#x2021;/g, '‡');
  152. str = str.replace(/&bull;|&#8226;|&#x2022;/g, '•');
  153. str = str.replace(/&hellip;|&#8230;|&#x2026;/g, '…');
  154. str = str.replace(/&permil;|&#8240;|&#x2030;/g, '‰');
  155. str = str.replace(/&prime;|&#8242;|&#x2032;/g, '′');
  156. str = str.replace(/&Prime;|&#8243;|&#x2033;/g, '″');
  157. str = str.replace(/&lsaquo;|&#8249;|&#x2039;/g, '‹');
  158. str = str.replace(/&rsaquo;|&#8250;|&#x203a;/g, '›');
  159. str = str.replace(/&oline;|&#8254;|&#x203e;/g, '‾');
  160. str = str.replace(/&euro;|&#8364;|&#x20ac;/g, '€');
  161. str = str.replace(/&trade;|&#8482;|&#x2122;/g, '™');
  162. str = str.replace(/&larr;|&#8592;|&#x2190;/g, '←');
  163. str = str.replace(/&uarr;|&#8593;|&#x2191;/g, '↑');
  164. str = str.replace(/&rarr;|&#8594;|&#x2192;/g, '→');
  165. str = str.replace(/&darr;|&#8595;|&#x2193;/g, '↓');
  166. str = str.replace(/&harr;|&#8596;|&#x2194;/g, '↔');
  167. str = str.replace(/&crarr;|&#8629;|&#x21b5;/g, '↵');
  168. str = str.replace(/&lceil;|&#8968;|&#x2308;/g, '⌈');
  169. str = str.replace(/&rceil;|&#8969;|&#x2309;/g, '⌉');
  170. str = str.replace(/&lfloor;|&#8970;|&#x230a;/g, '⌊');
  171. str = str.replace(/&rfloor;|&#8971;|&#x230b;/g, '⌋');
  172. str = str.replace(/&loz;|&#9674;|&#x25ca;/g, '◊');
  173. str = str.replace(/&spades;|&#9824;|&#x2660;/g, '♠');
  174. str = str.replace(/&clubs;|&#9827;|&#x2663;/g, '♣');
  175. str = str.replace(/&hearts;|&#9829;|&#x2665;/g, '♥');
  176. str = str.replace(/&diams;|&#9830;|&#x2666;/g, '♦');
  177. return str;
  178. }
  179. function strDiscode(str) {
  180. str = strNumDiscode(str);
  181. str = strGreeceDiscode(str);
  182. str = strcharacterDiscode(str);
  183. str = strOtherDiscode(str);
  184. return str;
  185. }
  186. function urlToHttpUrl(url, domain) {
  187. if (/^\/\//.test(url)) {
  188. return `https:${url}`;
  189. } else if (/^\//.test(url)) {
  190. return `https://${domain}${url}`;
  191. }
  192. return url;
  193. }
  194. export default {
  195. strDiscode,
  196. urlToHttpUrl,
  197. };