wxDiscode.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. function strNumDiscode(str) {
  2. str = str.replace(/∀/g, '∀');
  3. str = str.replace(/∂/g, '∂');
  4. str = str.replace(/&exists;/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. return str;
  40. }
  41. function strGreeceDiscode(str) {
  42. str = str.replace(/Α/g, 'Α');
  43. str = str.replace(/Β/g, 'Β');
  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. return str;
  96. }
  97. function strcharacterDiscode(str) {
  98. str = str.replace(/ /g, ' ');
  99. str = str.replace(/"/g, '"');
  100. str = str.replace(/&/g, '&');
  101. str = str.replace(/&lt;/g, '<');
  102. str = str.replace(/&gt;/g, '>');
  103. return str;
  104. }
  105. function strOtherDiscode(str) {
  106. str = str.replace(/&OElig;/g, 'Œ');
  107. str = str.replace(/&oelig;/g, 'œ');
  108. str = str.replace(/&Scaron;/g, 'Š');
  109. str = str.replace(/&scaron;/g, 'š');
  110. str = str.replace(/&Yuml;/g, 'Ÿ');
  111. str = str.replace(/&fnof;/g, 'ƒ');
  112. str = str.replace(/&circ;/g, 'ˆ');
  113. str = str.replace(/&tilde;/g, '˜');
  114. str = str.replace(/&ensp;/g, '');
  115. str = str.replace(/&emsp;/g, '');
  116. str = str.replace(/&thinsp;/g, '');
  117. str = str.replace(/&zwnj;/g, '');
  118. str = str.replace(/&zwj;/g, '');
  119. str = str.replace(/&lrm;/g, '');
  120. str = str.replace(/&rlm;/g, '');
  121. str = str.replace(/&ndash;/g, '–');
  122. str = str.replace(/&mdash;/g, '—');
  123. str = str.replace(/&lsquo;/g, '‘');
  124. str = str.replace(/&rsquo;/g, '’');
  125. str = str.replace(/&sbquo;/g, '‚');
  126. str = str.replace(/&ldquo;/g, '“');
  127. str = str.replace(/&rdquo;/g, '”');
  128. str = str.replace(/&bdquo;/g, '„');
  129. str = str.replace(/&dagger;/g, '†');
  130. str = str.replace(/&Dagger;/g, '‡');
  131. str = str.replace(/&bull;/g, '•');
  132. str = str.replace(/&hellip;/g, '…');
  133. str = str.replace(/&permil;/g, '‰');
  134. str = str.replace(/&prime;/g, '′');
  135. str = str.replace(/&Prime;/g, '″');
  136. str = str.replace(/&lsaquo;/g, '‹');
  137. str = str.replace(/&rsaquo;/g, '›');
  138. str = str.replace(/&oline;/g, '‾');
  139. str = str.replace(/&euro;/g, '€');
  140. str = str.replace(/&trade;/g, '™');
  141. str = str.replace(/&larr;/g, '←');
  142. str = str.replace(/&uarr;/g, '↑');
  143. str = str.replace(/&rarr;/g, '→');
  144. str = str.replace(/&darr;/g, '↓');
  145. str = str.replace(/&harr;/g, '↔');
  146. str = str.replace(/&crarr;/g, '↵');
  147. str = str.replace(/&lceil;/g, '⌈');
  148. str = str.replace(/&rceil;/g, '⌉');
  149. str = str.replace(/&lfloor;/g, '⌊');
  150. str = str.replace(/&rfloor;/g, '⌋');
  151. str = str.replace(/&loz;/g, '◊');
  152. str = str.replace(/&spades;/g, '♠');
  153. str = str.replace(/&clubs;/g, '♣');
  154. str = str.replace(/&hearts;/g, '♥');
  155. str = str.replace(/&diams;/g, '♦');
  156. return str;
  157. }
  158. function strMoreDiscode(str) {
  159. str = str.replace(/\r\n/g, '');
  160. str = str.replace(/\n/g, '');
  161. str = str.replace(/code/g, 'wxxxcode-style');
  162. return str;
  163. }
  164. function strDiscode(str) {
  165. str = strNumDiscode(str);
  166. str = strGreeceDiscode(str);
  167. str = strcharacterDiscode(str);
  168. str = strOtherDiscode(str);
  169. str = strMoreDiscode(str);
  170. return str;
  171. }
  172. function urlToHttpUrl(url, rep) {
  173. var patt1 = new RegExp('^//');
  174. var result = patt1.test(url);
  175. if (result) {
  176. url = rep + ':' + url;
  177. }
  178. return url;
  179. }
  180. module.exports = {
  181. strDiscode: strDiscode,
  182. urlToHttpUrl: urlToHttpUrl
  183. };