mid_pas.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import re
  2. def mid_pas(data, fol_num, include, in_c, toc_y):
  3. p = re.compile('{{{((?:(?:(?:\+|-)[0-5])|(?:#|@)(?:(?:[0-9a-f-A-F]{3}){1,2}|(?:\w+))|(?:#!(?:html|wiki|noin|folding|syntax)))(?:(?!{{{|}}}).)+)}}}', re.DOTALL)
  4. while(1):
  5. m = p.search(data)
  6. if(m):
  7. data = p.sub('###' + m.groups()[0] + '/###', data, 1)
  8. else:
  9. break
  10. com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL)
  11. while(1):
  12. m = com.search(data)
  13. if(m):
  14. data = com.sub('<code>' + m.groups()[0] + '</code>', data, 1)
  15. else:
  16. break
  17. com3 = re.compile('###((?:(?!\/###).)+)\/###', re.DOTALL)
  18. m = com3.search(data)
  19. while(1):
  20. m = com3.search(data)
  21. if(m):
  22. data = com3.sub('{{{' + m.groups()[0] + '}}}', data, 1)
  23. else:
  24. break
  25. com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  26. da_com = com2.findall(data)
  27. for com_da in da_com:
  28. mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
  29. mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
  30. data = com2.sub(mid_data, data, 1)
  31. while(1):
  32. is_it = com.search(data)
  33. if(is_it):
  34. it_d = is_it.groups()[0]
  35. big_a = re.compile("^\+([1-5]) (.*)$", re.DOTALL)
  36. big = big_a.search(it_d)
  37. small_a = re.compile("^\-([1-5]) (.*)$", re.DOTALL)
  38. small = small_a.search(it_d)
  39. color_b = re.compile("^(#(?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
  40. color_2 = color_b.search(it_d)
  41. color_c = re.compile("^#(\w+) (.*)$", re.DOTALL)
  42. color_3 = color_c.search(it_d)
  43. back_a = re.compile("^@((?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
  44. back = back_a.search(it_d)
  45. back_c = re.compile("^@(\w+) (.*)$", re.DOTALL)
  46. back_3 = back_c.search(it_d)
  47. include_out_a = re.compile("^#!noin (.*)$", re.DOTALL)
  48. include_out = include_out_a.search(it_d)
  49. div_a = re.compile("^#!wiki style=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\r\n(.*)$", re.DOTALL)
  50. div = div_a.search(it_d)
  51. html_a = re.compile("^#!html (.*)$", re.DOTALL)
  52. html_d = html_a.search(it_d)
  53. fol_a = re.compile("^#!folding ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
  54. fol = fol_a.search(it_d)
  55. syn_a = re.compile("^#!syntax ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
  56. syn = syn_a.search(it_d)
  57. if(big):
  58. big_d = big.groups()
  59. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  60. elif(small):
  61. sm_d = small.groups()
  62. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  63. elif(color_2):
  64. c_d_2 = color_2.groups()
  65. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  66. elif(color_3):
  67. c_d_3 = color_3.groups()
  68. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  69. elif(back):
  70. back_d_1 = back.groups()
  71. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  72. elif(back_3):
  73. back_d_3 = back_3.groups()
  74. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  75. elif(div):
  76. div_d = div.groups()
  77. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  78. elif(html_d):
  79. data = com.sub(html_d.groups()[0], data, 1)
  80. elif(fol):
  81. fol_d = fol.groups()
  82. if(toc_y != 0):
  83. 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) + \
  84. "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>]</div><div id='folding_" + str(fol_num + 2) + \
  85. "' style='display: none;'>[<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + \
  86. "); folding(" + str(fol_num) + ");'>접기</a>]</div><div id='folding_" + str(fol_num) + "' style='display: none;'><br>" + fol_d[1] + \
  87. "</div></div>", data, 1)
  88. fol_num += 3
  89. else:
  90. data = com.sub("<div>" + fol_d[0] + "<br><br>" + fol_d[1] + "</div>", data, 1)
  91. elif(syn):
  92. syn_d = syn.groups()
  93. tax_d = syn_d[1].replace(' ', '<space>')
  94. tax_d = tax_d.replace('\r\n', '<isbr>')
  95. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '"><code>' + tax_d + '</code></code></pre>', data, 1)
  96. elif(include_out):
  97. if((include or in_c) == 1):
  98. data = com.sub("", data, 1)
  99. else:
  100. data = com.sub(include_out.groups()[0], data, 1)
  101. else:
  102. data = com.sub(it_d, data, 1)
  103. else:
  104. break
  105. com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  106. da_com = com2.findall(data)
  107. for com_da in da_com:
  108. mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
  109. mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
  110. data = com2.sub(mid_data, data, 1)
  111. return([data, fol_num])