editorImg.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. export function formatRichText(html) {
  11. let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
  12. match = match
  13. .replace(/style="[^"]+"/gi, "")
  14. .replace(/style='[^']+'/gi, "");
  15. match = match
  16. .replace(/width="[^"]+"/gi, "")
  17. .replace(/width='[^']+'/gi, "");
  18. match = match
  19. .replace(/height="[^"]+"/gi, "")
  20. .replace(/height='[^']+'/gi, "");
  21. return match;
  22. });
  23. newContent = newContent.replace(
  24. /style="[^"]+"/gi,
  25. function (match, capture) {
  26. match = match
  27. .replace(/width:[^;]+;/gi, "max-width:100%;")
  28. .replace(/width:[^;]+;/gi, "max-width:100%;");
  29. return match;
  30. }
  31. );
  32. // newContent = newContent.replace(/<br[^>]*\/>/gi, "");
  33. newContent = newContent.replace(
  34. /\<img/gi,
  35. '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"'
  36. );
  37. return newContent;
  38. }