unescapeHtml.js 872 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. export function unescape(html) {
  2. return html
  3. .replace(html ? /&(?!#?\w+;)/g : /&/g, '')
  4. .replace(/&lt;/g, "<")
  5. .replace(/&gt;/g, ">")
  6. .replace(/&quot;/g, "\"")
  7. .replace(/&#39;/g, "\'")
  8. .replace(/nbsp;/g,"\u00a0")
  9. .replace(/&amp;/g,"")
  10. }
  11. /**
  12. * 反转义html
  13. * @param html
  14. * @returns {*}
  15. */
  16. export function unescapeHtml(html) {
  17. return html
  18. .replace(html ? /&(?!#?\w+;)/g : /&/g, '')
  19. .replace(/&lt;/g, "<")
  20. .replace(/&gt;/g, ">")
  21. .replace(/&quot;/g, "\"")
  22. .replace(/&#39;/g, "\'")
  23. .replace(/nbsp;/g,"\u00a0")
  24. .replace(/&amp;/g,"")
  25. }
  26. /**
  27. * 转义html
  28. * @param html
  29. * @returns {*}
  30. */
  31. export function escapeHtml(html) {
  32. return html
  33. .replace(/&/g, '&amp;')
  34. .replace(/</g, '&lt;')
  35. .replace(/"/g, '&quot;')
  36. .replace(/'/g, "&#39;")
  37. .replace(/>/g, '&gt;')
  38. .replace(/\u00a0/g,"nbsp;")
  39. }