handler.sjs 1.8 KB

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