handler.wxs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Parser/trees/cssHandler.wxs
  2. var textTag = {
  3. abbr: true,
  4. b: true,
  5. big: true,
  6. code: true,
  7. del: true,
  8. em: true,
  9. font: true,
  10. i: true,
  11. ins: true,
  12. label: true,
  13. mark: true,
  14. q: true,
  15. s: true,
  16. small: true,
  17. span: true,
  18. strong: true,
  19. u: true
  20. }
  21. module.exports = {
  22. getStyle: function(style, display) {
  23. var res = "";
  24. var reg = getRegExp("float\s*:\s*[^;]*", "i");
  25. if (reg.test(style)) res += reg.exec(style)[0];
  26. reg = getRegExp("margin[^;]*", "gi");
  27. var margin = reg.exec(style);
  28. while (margin) {
  29. res += (';' + margin[0]);
  30. margin = reg.exec(style);
  31. }
  32. reg = getRegExp("display\s*:\s*([^;]*)", "i");
  33. if (reg.test(style) && reg.exec(style)[1] != "flex") res += (';' + reg.exec(style)[0]);
  34. else res += (';display:' + display);
  35. reg = getRegExp("flex\s*:[^;]*", "i");
  36. if (reg.test(style)) res += (';' + reg.exec(style)[0]);
  37. reg = getRegExp("[^;\s]*width[^;]*", "ig");
  38. var width = reg.exec(style);
  39. while (width) {
  40. res += (';' + width[0]);
  41. width = reg.exec(style);
  42. }
  43. return res;
  44. },
  45. setImgStyle: function(item, imgMode, imgLoad) {
  46. if (imgMode == "widthFix")
  47. item.attrs.style += ";height:auto !important";
  48. if (getRegExp("[^-]width[^pev;]+").test(";" + item.attrs.style))
  49. item.attrs.style += ";width:100%";
  50. item.attrs.style = item.attrs.style.replace(getRegExp('margin[^;]*', "gi"), "");
  51. if (!imgLoad) {
  52. delete item.attrs.src;
  53. item.attrs.style += ";width:5px !important;height:5px !important"
  54. }
  55. return [item];
  56. },
  57. setStyle: function(item) {
  58. if (getRegExp("[^-]width[^pev;]+").test(";" + item.attrs.style))
  59. item.attrs.style += ";width:100%";
  60. item.attrs.style = item.attrs.style.replace(getRegExp('margin[^;]*', "gi"), "");
  61. return [item];
  62. },
  63. isContinue: function(item) {
  64. if (textTag[item.name])
  65. return false;
  66. if (!item["continue"])
  67. return true;
  68. else if (item.name == 'a')
  69. return true;
  70. return false;
  71. }
  72. }