mid_pas.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import re
  2. from urllib import parse
  3. def mid_pas(data, fol_num, include, in_c, toc_y):
  4. syntax = 0
  5. folding_test = 0
  6. while 1:
  7. is_it = com.search(data)
  8. if is_it:
  9. it_d = is_it.groups()[0]
  10. big_a = re.compile("^\+([1-5]) (.*)$", re.DOTALL)
  11. big = big_a.search(it_d)
  12. small_a = re.compile("^\-([1-5]) (.*)$", re.DOTALL)
  13. small = small_a.search(it_d)
  14. color_b = re.compile("^(#(?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
  15. color_2 = color_b.search(it_d)
  16. color_c = re.compile("^#(\w+) (.*)$", re.DOTALL)
  17. color_3 = color_c.search(it_d)
  18. back_a = re.compile("^@((?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
  19. back = back_a.search(it_d)
  20. back_c = re.compile("^@(\w+) (.*)$", re.DOTALL)
  21. back_3 = back_c.search(it_d)
  22. include_out_a = re.compile("^#!noin ?(.*)$", re.DOTALL)
  23. include_out = include_out_a.search(it_d)
  24. div_a = re.compile("^#!wiki style=(?:"|')((?:(?!"|').)*)(?:"|')\r\n(.*)$", re.DOTALL)
  25. div = div_a.search(it_d)
  26. html_a = re.compile("^#!html ?(.*)$", re.DOTALL)
  27. html_d = html_a.search(it_d)
  28. fol_a = re.compile("^#!folding ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
  29. fol = fol_a.search(it_d)
  30. syn_a = re.compile("^#!syntax ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
  31. syn = syn_a.search(it_d)
  32. if big:
  33. big_d = big.groups()
  34. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  35. elif small:
  36. sm_d = small.groups()
  37. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  38. elif color_2:
  39. c_d_2 = color_2.groups()
  40. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  41. elif color_3:
  42. c_d_3 = color_3.groups()
  43. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  44. elif back:
  45. back_d_1 = back.groups()
  46. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  47. elif back_3:
  48. back_d_3 = back_3.groups()
  49. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  50. elif div:
  51. div_d = div.groups()
  52. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  53. elif html_d:
  54. data = com.sub(html_d.groups()[0], data, 1)
  55. elif fol:
  56. fol_d = fol.groups()
  57. if toc_y != 0:
  58. data = com.sub("<div>" + fol_d[0] + " <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'>" + "[<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>]</div>" + "<div id='folding_" + str(fol_num + 2) + "' style='display: none;'>[" + "<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + ");" + " folding(" + str(fol_num) + ");'>접기</a>]</div><div id='folding_" + str(fol_num) + "' style='display: none;'>" + "<br>" + fol_d[1] + "</div></div>", data, 1)
  59. fol_num += 3
  60. else:
  61. data = com.sub("<div>" + fol_d[0] + "<br><br>" + fol_d[1] + "</div>", data, 1)
  62. elif syn:
  63. if syntax == 0:
  64. data += '<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script><script>hljs.initHighlightingOnLoad();</script>'
  65. syntax = 1
  66. syn_d = syn.groups()
  67. tax_d = syn_d[1].replace(' ', '<space>')
  68. tax_d = tax_d.replace('\r\n', '<isbr>')
  69. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '"><code>' + tax_d + '</code></code></pre>', data, 1)
  70. elif include_out:
  71. if (include or in_c) == 1:
  72. data = com.sub("", data, 1)
  73. else:
  74. data = com.sub(include_out.groups()[0], data, 1)
  75. else:
  76. data = com.sub(it_d, data, 1)
  77. else:
  78. break
  79. return [data, fol_num]