handler.wxs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var inlineTags = {
  2. abbr: 1,
  3. b: 1,
  4. big: 1,
  5. code: 1,
  6. del: 1,
  7. em: 1,
  8. i: 1,
  9. ins: 1,
  10. label: 1,
  11. q: 1,
  12. small: 1,
  13. span: 1,
  14. strong: 1
  15. }
  16. module.exports = {
  17. // 从 rich-text 顶层标签的样式中取出一些给 rich-text
  18. getStyle: function(style, display) {
  19. if (style) {
  20. var i, j, res = "";
  21. if ((i = style.indexOf("display")) != -1)
  22. res = style.substring(i, (j = style.indexOf(';', i)) == -1 ? style.length : j);
  23. else res = "display:" + display;
  24. if (style.indexOf("flex") != -1) res += ';' + style.match(getRegExp("flex[:-][^;]+/g")).join(';');
  25. return res;
  26. } else return "display:" + display;
  27. },
  28. // 处理懒加载
  29. getNode: function(item, imgLoad) {
  30. if (!imgLoad) {
  31. delete item.attrs.src;
  32. item.attrs.style += ";width:20px !important;height:20px !important";
  33. }
  34. return [item];
  35. },
  36. // 是否通过 rich-text 显示
  37. useRichText: function(item) {
  38. // rich-text 不支持 inline
  39. if (item.c || inlineTags[item.name] || (item.attrs.style && item.attrs.style.indexOf("display:inline") != -1)) return false;
  40. return true;
  41. }
  42. }