mark.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. from bottle import request, app
  2. from bottle.ext import beaker
  3. from urllib import parse
  4. import json
  5. import sqlite3
  6. import time
  7. import re
  8. import hashlib
  9. import html
  10. json_data = open('set.json').read()
  11. set_data = json.loads(json_data)
  12. conn = sqlite3.connect(set_data['db'] + '.db')
  13. curs = conn.cursor()
  14. session_opts = {
  15. 'session.type': 'file',
  16. 'session.data_dir': './app_session/',
  17. 'session.auto': 1
  18. }
  19. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  20. def get_time():
  21. now = time.localtime()
  22. date = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
  23. return(date)
  24. def ip_check():
  25. session = request.environ.get('beaker.session')
  26. if(session.get('Now') == 1):
  27. ip = format(session['DREAMER'])
  28. else:
  29. if(request.environ.get('HTTP_X_FORWARDED_FOR')):
  30. ip = request.environ.get('HTTP_X_FORWARDED_FOR')
  31. else:
  32. ip = request.environ.get('REMOTE_ADDR')
  33. return(ip)
  34. def url_pas(data):
  35. return(parse.quote(data).replace('/','%2F'))
  36. def sha224(data):
  37. return(hashlib.sha224(bytes(data, 'utf-8')).hexdigest())
  38. def savemark(data):
  39. data = re.sub("\[date\(now\)\]", get_time(), data)
  40. if(not re.search("\.", ip_check())):
  41. name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
  42. else:
  43. name = ip_check()
  44. data = re.sub("\[name\]", name, data)
  45. return(data)
  46. def send_p(d):
  47. d = html.escape(d)
  48. js_p = re.compile('javascript:', re.I)
  49. d = js_p.sub('', d)
  50. d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)
  51. return(d)
  52. def table_p(d, d2):
  53. alltable = 'style="'
  54. celstyle = 'style="'
  55. rowstyle = 'style="'
  56. row = ''
  57. cel = ''
  58. table_w = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", d)
  59. table_h = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", d)
  60. table_a = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", d)
  61. if(table_w):
  62. alltable += 'width: ' + table_w.groups()[0] + ';'
  63. if(table_h):
  64. alltable += 'height: ' + table_h.groups()[0] + ';'
  65. if(table_a):
  66. if(table_a.groups()[0] == 'right'):
  67. alltable += 'float: right;'
  68. elif(table_a.groups()[0] == 'center'):
  69. alltable += 'margin: auto;'
  70. table_t_a = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  71. if(table_t_a):
  72. if(table_t_a.groups()[0] == 'right'):
  73. alltable += 'text-align: right;'
  74. elif(table_t_a.groups()[0] == 'center'):
  75. alltable += 'text-align: center;'
  76. row_t_a = re.search("&lt;row\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  77. if(row_t_a):
  78. if(row_t_a.groups()[0] == 'right'):
  79. rowstyle += 'text-align: right;'
  80. elif(row_t_a.groups()[0] == 'center'):
  81. rowstyle += 'text-align: center;'
  82. else:
  83. rowstyle += 'text-align: left;'
  84. table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", d)
  85. if(table_cel):
  86. cel = 'colspan="' + table_cel.groups()[0] + '"'
  87. else:
  88. cel = 'colspan="' + str(round(len(d2) / 2)) + '"'
  89. table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", d)
  90. if(table_row):
  91. row = 'rowspan="' + table_row.groups()[0] + '"'
  92. row_bgcolor_1 = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", d)
  93. row_bgcolor_2 = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", d)
  94. row_bgcolor_3 = re.search("&lt;rowbgcolor=(\w+)&gt;", d)
  95. if(row_bgcolor_1):
  96. rowstyle += 'background: ' + row_bgcolor_1.groups()[0] + ';'
  97. elif(row_bgcolor_2):
  98. rowstyle += 'background: ' + row_bgcolor_2.groups()[0] + ';'
  99. elif(row_bgcolor_3):
  100. rowstyle += 'background: ' + row_bgcolor_3.groups()[0] + ';'
  101. table_border_1 = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", d)
  102. table_border_2 = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", d)
  103. table_border_3 = re.search("&lt;table\s?bordercolor=(\w+)&gt;", d)
  104. if(table_border_1):
  105. alltable += 'border: ' + table_border_1.groups()[0] + ' 2px solid;'
  106. elif(table_border_2):
  107. alltable += 'border: ' + table_border_2.groups()[0] + ' 2px solid;'
  108. elif(table_border_3):
  109. alltable += 'border: ' + table_border_3.groups()[0] + ' 2px solid;'
  110. table_bgcolor_1 = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", d)
  111. table_bgcolor_2 = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", d)
  112. table_bgcolor_3 = re.search("&lt;table\s?bgcolor=(\w+)&gt;", d)
  113. if(table_bgcolor_1):
  114. alltable += 'background: ' + table_bgcolor_1.groups()[0] + ';'
  115. elif(table_bgcolor_2):
  116. alltable += 'background: ' + table_bgcolor_2.groups()[0] + ';'
  117. elif(table_bgcolor_3):
  118. alltable += 'background: ' + table_bgcolor_3.groups()[0] + ';'
  119. bgcolor_1 = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", d)
  120. bgcolor_2 = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", d)
  121. bgcolor_3 = re.search("&lt;bgcolor=(\w+)&gt;", d)
  122. if(bgcolor_1):
  123. celstyle += 'background: ' + bgcolor_1.groups()[0] + ';'
  124. elif(bgcolor_2):
  125. celstyle += 'background: ' + bgcolor_2.groups()[0] + ';'
  126. elif(bgcolor_3):
  127. celstyle += 'background: ' + bgcolor_3.groups()[0] + ';'
  128. st_bgcolor_1 = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", d)
  129. st_bgcolor_2 = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", d)
  130. st_bgcolor_3 = re.search("&lt;(\w+)&gt;", d)
  131. if(st_bgcolor_1):
  132. celstyle += 'background: ' + st_bgcolor_1.groups()[0] + ';'
  133. elif(st_bgcolor_2):
  134. celstyle += 'background: ' + st_bgcolor_2.groups()[0] + ';'
  135. elif(st_bgcolor_3):
  136. celstyle += 'background: ' + st_bgcolor_3.groups()[0] + ';'
  137. n_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", d)
  138. n_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", d)
  139. if(n_width):
  140. celstyle += 'width: ' + n_width.groups()[0] + ';'
  141. if(n_height):
  142. celstyle += 'height: ' + n_height.groups()[0] + ';'
  143. text_right = re.search("&lt;\)&gt;", d)
  144. text_center = re.search("&lt;:&gt;", d)
  145. text_left = re.search("&lt;\(&gt;", d)
  146. if(text_right):
  147. celstyle += 'text-align: right;'
  148. elif(text_center):
  149. celstyle += 'text-align: center;'
  150. elif(text_left):
  151. celstyle += 'text-align: left;'
  152. alltable += '"'
  153. celstyle += '"'
  154. rowstyle += '"'
  155. return([alltable, rowstyle, celstyle, row, cel])
  156. def html_pas(data):
  157. data = re.sub("%phtml%(?P<in>(?:\/)?(?:a|div|span|embed|iframe)(?:\s[^%]*)?)%phtml%", "<\g<in>>", data)
  158. pas_d = re.findall("<((div|span|embed|iframe)(?:\s[^>]*))>", data)
  159. for p_d in pas_d:
  160. if(re.search("<(\/" + p_d[1] + ")>", data)):
  161. url_d = re.search('src=(?:"|\')?(http(s)?:\/\/([^\/]*)\/(?:[^"\' ]*))(?:"|\')?', p_d[0])
  162. if(url_d):
  163. check = url_d.groups()
  164. if(check[2] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "tvple.com", "www.google.com"]):
  165. pas_end = p_d[0].replace('®', '&reg')
  166. else:
  167. pas_end = re.sub('src=(?:"|\')([^"\']*)(?:"|\')', '', p_d[0])
  168. else:
  169. pas_end = p_d[0]
  170. pas_end = re.sub('position:(?: +)?[^ ;]*;?', '', pas_end)
  171. try:
  172. if(check[1] != None):
  173. data = re.sub("<((?:\/)?" + p_d[1] + "(?:\s[^>]*))>", "%phtml%" + pas_end + "%phtml%", data, 1)
  174. data = re.sub("<\/" + p_d[1] + ">", "%phtml%/" + p_d[1] + "%phtml%", data, 1)
  175. else:
  176. data = re.sub("<((?:\/)?" + p_d[1] + "(?:\s[^>]*))>", "[[" + check[0] + "]]", data, 1)
  177. data = re.sub("<\/" + p_d[1] + ">", "", data, 1)
  178. except:
  179. data = re.sub("<((?:\/)?" + p_d[1] + "(?:\s[^>]*))>", "%phtml%" + pas_end + "%phtml%", data, 1)
  180. data = re.sub("<\/" + p_d[1] + ">", "%phtml%/" + p_d[1] + "%phtml%", data, 1)
  181. else:
  182. data = re.sub("<((?:\/)?" + p_d[1] + "(?:\s[^>]*))>", '&lt;' + p_d[0] + '&gt;', data, 1)
  183. break
  184. data = html.escape(data)
  185. js_p = re.compile('javascript:', re.I)
  186. data = js_p.sub('', data)
  187. pas_2 = re.findall("%phtml%(?P<in>(?:\/)?(?:div|span|embed|iframe)(?:\s(?:(?!%phtml%).)*)?)%phtml%", data)
  188. for p_d_2 in pas_2:
  189. data = re.sub("%phtml%(?P<in>(?:\/)?(?:div|span|embed|iframe)(?:\s(?:(?!%phtml%).)*)?)%phtml%", '<' + p_d_2.replace("&#x27;", "'").replace('&quot;', '"') + '>', data, 1)
  190. return(data)
  191. def mid_pas(data, fol_num, include, in_c):
  192. com = re.compile("{{{((?:(?!{|}).)*)}}}", re.DOTALL)
  193. while(1):
  194. is_it = com.search(data)
  195. if(is_it):
  196. it_d = is_it.groups()[0]
  197. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  198. big = big_a.search(it_d)
  199. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  200. small = small_a.search(it_d)
  201. color_a = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  202. color = color_a.search(it_d)
  203. color_b = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  204. color_2 = color_b.search(it_d)
  205. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  206. color_3 = color_c.search(it_d)
  207. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  208. back = back_a.search(it_d)
  209. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  210. back_2 = back_b.search(it_d)
  211. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  212. back_3 = back_c.search(it_d)
  213. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  214. include_out = include_out_a.search(it_d)
  215. div_a = re.compile("^#!wiki\sstyle=(?:&quot;|&apos;)((?:(?!&quot;|&apos;).)*)(?:&quot;|&apos;)\r\n(.*)$", re.DOTALL)
  216. div = div_a.search(it_d)
  217. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  218. html = html_a.search(it_d)
  219. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  220. fol = fol_a.search(it_d)
  221. syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
  222. syn = syn_a.search(it_d)
  223. if(big):
  224. big_d = big.groups()
  225. data = com.sub('<span class="font-size-' + big_d[0] + '">' + big_d[1] + '</span>', data, 1)
  226. elif(small):
  227. sm_d = small.groups()
  228. data = com.sub('<span class="font-size-small-' + sm_d[0] + '">' + sm_d[1] + '</span>', data, 1)
  229. elif(color):
  230. c_d_1 = color.groups()
  231. data = com.sub('<span style="color: ' + c_d_1[0] + '">' + c_d_1[1] + '</span>', data, 1)
  232. elif(color_2):
  233. c_d_2 = color_2.groups()
  234. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  235. elif(color_3):
  236. c_d_3 = color_3.groups()
  237. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  238. elif(back):
  239. back_d_1 = back.groups()
  240. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  241. elif(back_2):
  242. back_d_2 = back_2.groups()
  243. data = com.sub('<span style="background: #' + back_d_2[0] + '">' + back_d_2[1] + '</span>', data, 1)
  244. elif(back_3):
  245. back_d_3 = back_3.groups()
  246. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  247. elif(div):
  248. div_d = div.groups()
  249. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  250. elif(html):
  251. data = com.sub(html.groups()[0], data, 1)
  252. elif(fol):
  253. fol_d = fol.groups()
  254. data = com.sub( "<div> \
  255. " + fol_d[0] + " \
  256. <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'> \
  257. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>] \
  258. </div> \
  259. <div id='folding_" + str(fol_num + 2) + "' style='display: none;'> \
  260. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>접기</a>] \
  261. </div> \
  262. <div id='folding_" + str(fol_num) + "' style='display: none;'> \
  263. <br> \
  264. " + fol_d[1] + " \
  265. </div> \
  266. </div>", data, 1)
  267. fol_num += 3
  268. elif(syn):
  269. syn_d = syn.groups()
  270. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '">' + re.sub('\r\n', '<isbr>', re.sub(' ', '<space>', syn_d[1])) + '</code></pre>', data, 1)
  271. elif(include_out):
  272. if((include or in_c) == 1):
  273. data = com.sub("", data, 1)
  274. else:
  275. data = com.sub(include_out.groups()[0], data, 1)
  276. else:
  277. data = com.sub('<code>' + it_d + '</code>', data, 1)
  278. else:
  279. break
  280. com = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  281. da_com = com.findall(data)
  282. for com_da in da_com:
  283. mid_data = re.sub("<\/span>", "}}}", com_da)
  284. mid_data = re.sub("<\/div>", "}}}", mid_data)
  285. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  286. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  287. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  288. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  289. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=\"\g<in>\"\n", mid_data)
  290. mid_data = mid_data.replace('<', '&lt;').replace('>', '&gt;')
  291. mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
  292. data = com.sub(mid_data, data, 1)
  293. return([data, fol_num])
  294. def toc_pas(data, title, num):
  295. i = [0, 0, 0, 0, 0, 0, 0]
  296. last = 0
  297. toc_c = -1
  298. toc_d = -1
  299. span = ''
  300. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  301. while(1):
  302. i[0] += 1
  303. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
  304. if(m):
  305. result = m.groups()
  306. wiki = len(result[0])
  307. if(last < wiki):
  308. last = wiki
  309. else:
  310. last = wiki
  311. if(wiki == 1):
  312. i[2] = 0
  313. i[3] = 0
  314. i[4] = 0
  315. i[5] = 0
  316. i[6] = 0
  317. elif(wiki == 2):
  318. i[3] = 0
  319. i[4] = 0
  320. i[5] = 0
  321. i[6] = 0
  322. elif(wiki == 3):
  323. i[4] = 0
  324. i[5] = 0
  325. i[6] = 0
  326. elif(wiki == 4):
  327. i[5] = 0
  328. i[6] = 0
  329. elif(wiki == 5):
  330. i[6] = 0
  331. if(wiki == 1):
  332. i[1] += 1
  333. elif(wiki == 2):
  334. i[2] += 1
  335. elif(wiki == 3):
  336. i[3] += 1
  337. elif(wiki == 4):
  338. i[4] += 1
  339. elif(wiki == 5):
  340. i[5] += 1
  341. else:
  342. i[6] += 1
  343. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  344. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  345. toc = re.sub("0\.", '', toc)
  346. toc = re.sub("#\.", '.', toc)
  347. toc = re.sub("\.$", '', toc)
  348. if(toc_c == -1):
  349. margin = 'style="margin-top: 30px;"'
  350. toc_c = toc.count('.')
  351. else:
  352. toc_d = toc.count('.')
  353. if(toc_c == toc_d):
  354. margin = 'style="margin-top: 30px;"'
  355. else:
  356. if(toc_d < toc_c):
  357. margin = 'style="margin-top: 30px;"'
  358. else:
  359. margin = ''
  360. toc_c = toc_d
  361. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  362. if(test):
  363. g = test.groups()
  364. if(g[4]):
  365. span = '<span style="margin-left: 5px;"></span>' * 4
  366. elif(g[3]):
  367. span = '<span style="margin-left: 5px;"></span>' * 3
  368. elif(g[2]):
  369. span = '<span style="margin-left: 5px;"></span>' * 2
  370. elif(g[1]):
  371. span = '<span style="margin-left: 5px;"></span>'
  372. else:
  373. span = ''
  374. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  375. c = re.sub(" $", "", result[1])
  376. d = c
  377. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  378. edit_d = ''
  379. if(num != 0):
  380. edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
  381. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' + toc + '.<span style="margin-left: 5px;"></span></a> ' + d + edit_d + '</h' + str(wiki) + '><hr style="margin-top: -5px;">', data, 1)
  382. else:
  383. rtoc += '</div>'
  384. break
  385. data = re.sub("\[목차\]", rtoc, data)
  386. return(data)
  387. def backlink_plus(name, link, backtype, num):
  388. if(num == 1):
  389. curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
  390. y = curs.fetchall()
  391. if(not y):
  392. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  393. def cat_plus(name, link, num):
  394. if(num == 1):
  395. curs.execute("select title from cat where title = ? and cat = ?", [link, name])
  396. y = curs.fetchall()
  397. if(not y):
  398. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  399. def namumark(title, data, num, in_c):
  400. data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
  401. data = html_pas(data)
  402. fol_num = 0
  403. var_d = mid_pas(data, fol_num, 0, in_c)
  404. data = var_d[0]
  405. fol_num = var_d[1]
  406. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
  407. while(1):
  408. m = include.search(data)
  409. if(m):
  410. results = m.groups()
  411. if(results[0] == title):
  412. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  413. else:
  414. curs.execute("select data from data where title = ?", [results[0]])
  415. in_con = curs.fetchall()
  416. backlink_plus(title, results[0], 'include', num)
  417. if(in_con):
  418. in_data = in_con[0][0]
  419. in_data = include.sub("", in_data)
  420. in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
  421. in_data = html_pas(in_data)
  422. var_d = mid_pas(in_data, fol_num, 1, in_c)
  423. in_data = var_d[0]
  424. fol_num = var_d[1]
  425. if(results[1]):
  426. a = results[1]
  427. while(1):
  428. g = re.search("([^= ,]*)\=([^,]*)", a)
  429. if(g):
  430. result = g.groups()
  431. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  432. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  433. else:
  434. break
  435. in_data = toc_pas(in_data, results[0], num)
  436. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  437. else:
  438. data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  439. else:
  440. break
  441. data = re.sub("##\s?(?P<in>[^\n]*)\n", "", data)
  442. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  443. data = savemark(data)
  444. while(1):
  445. r_data = re.search('^#(?:redirect|넘겨주기) ([^\n]*)', data)
  446. if(r_data):
  447. n_data = r_data.groups()
  448. n_s_data = re.sub("\\\#", "<sharp>", n_data[0])
  449. s_data = re.search("^([^\n#]*)(#(?:[^\n]*))?$", n_s_data)
  450. r_s_data = s_data.groups()
  451. n_sharp = re.sub("<sharp>", "#", r_s_data[0])
  452. if(r_s_data[1]):
  453. plus = r_s_data[1]
  454. else:
  455. plus = ''
  456. data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + re.sub('%0D$', '', url_pas(n_sharp)) + '/from/' + url_pas(title) + plus + '" />', data, 1)
  457. backlink_plus(title, n_data[0], 'redirect', num)
  458. else:
  459. break
  460. data = '\r\n' + data + '\r\n'
  461. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  462. while(1):
  463. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  464. if(m):
  465. result = m.groups()
  466. blockquote = result[0]
  467. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  468. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  469. else:
  470. break
  471. if(not re.search('\[목차\]', data)):
  472. if(not re.search('\[목차\(없음\)\]', data)):
  473. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  474. else:
  475. data = re.sub("\[목차\(없음\)\]", "", data)
  476. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  477. data = toc_pas(data, title, num)
  478. category = ''
  479. while(1):
  480. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  481. if(m):
  482. g = m.groups()
  483. if(title != g[0]):
  484. cat_plus(title, g[0], num)
  485. if(category == ''):
  486. curs.execute("select title from data where title = ?", [g[0]])
  487. exists = curs.fetchall()
  488. if(exists):
  489. red = ""
  490. else:
  491. red = 'class="not_thing"'
  492. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  493. else:
  494. curs.execute("select title from data where title = ?", [g[0]])
  495. exists = curs.fetchall()
  496. if(exists):
  497. red = ""
  498. else:
  499. red = 'class="not_thing"'
  500. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  501. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  502. else:
  503. break
  504. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  505. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  506. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)+)(?:~~|--)', '<s>\g<in></s>', data)
  507. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  508. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  509. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  510. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  511. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  512. <tbody> \
  513. <tr> \
  514. <td> \
  515. \g<in> \
  516. </td> \
  517. </tr> \
  518. </tbody> \
  519. </table>', data)
  520. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  521. \g<in> \
  522. <rp>(</rp> \
  523. <rt>\g<out></rt> \
  524. <rp>)</rp> \
  525. </ruby>', data)
  526. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  527. if(test):
  528. for wiki in test:
  529. if(wiki[1]):
  530. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  531. else:
  532. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  533. while(1):
  534. m = re.search("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  535. if(m):
  536. img_d = m.groups()
  537. if(img_d):
  538. if(img_d[0] == '파일' and not re.search("^파일:([^\n]*)", title)):
  539. backlink_plus(title, '파일:' + img_d[1], 'file', num)
  540. width = ''
  541. height = ''
  542. if(img_d[2]):
  543. width_r = re.search("width=([^ \n&]*)", img_d[2])
  544. height_r = re.search("height=([^ \n&]*)", img_d[2])
  545. if(width_r):
  546. width_d = width_r.groups()
  547. width = width_d[0]
  548. if(height_r):
  549. height_d = height_r.groups()
  550. height = height_d[0]
  551. if(img_d[0] == '파일'):
  552. img_e = re.search('^(.+)(\.(?:.+))$', img_d[1]).groups()
  553. data = re.sub("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + img_d[1] + '"><img src="/image/' + sha224(img_e[0]) + img_e[1] + '" width="' + width + '" height="' + height + '"></a>', data, 1)
  554. else:
  555. data = re.sub("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", '<img src="' + img_d[1] + '" width="' + width + '" height="' + height + '">', data, 1)
  556. else:
  557. break
  558. else:
  559. break
  560. data = re.sub("\[br\]",'<br>', data)
  561. while(1):
  562. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  563. m = com.search(data)
  564. if(m):
  565. src = ''
  566. width = '560'
  567. height = '315'
  568. time = '0'
  569. result = m.groups()
  570. if(result[0]):
  571. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
  572. if(yudt):
  573. if(yudt.groups()[0]):
  574. src = yudt.groups()[0]
  575. elif(yudt.groups()[1]):
  576. src = yudt.groups()[1]
  577. elif(yudt.groups()[2]):
  578. src = yudt.groups()[2]
  579. else:
  580. src = ''
  581. if(result[1]):
  582. mdata = re.search('width=([0-9%]*)', result[1])
  583. if(mdata):
  584. width = mdata.groups()[0]
  585. mdata = re.search('height=([0-9%]*)', result[1])
  586. if(mdata):
  587. height = mdata.groups()[0]
  588. mdata = re.search('time=([0-9]*)', result[1])
  589. if(mdata):
  590. time = mdata.groups()[0]
  591. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  592. else:
  593. break
  594. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  595. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  596. for i in a:
  597. b = re.search('(.*)\/', title)
  598. if(b):
  599. m = b.groups()
  600. if(i):
  601. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  602. else:
  603. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  604. else:
  605. if(i):
  606. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  607. else:
  608. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  609. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  610. while(1):
  611. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  612. if(m):
  613. result = m.groups()
  614. rep = result[0]
  615. rep = re.sub("\\\#", "<sharp>", rep)
  616. a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
  617. results = a.groups()
  618. aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
  619. if(results[1]):
  620. g = re.sub("<sharp>", "#", results[1])
  621. else:
  622. g = re.sub("<sharp>", "#", results[0])
  623. results = aa.groups()
  624. if(not results[1]):
  625. sharp = ''
  626. else:
  627. sharp = results[1]
  628. b = re.search("^http(?:s)?:\/\/", results[0])
  629. if(b):
  630. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" rel="nofollow" target="_blank" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  631. else:
  632. if(results[0] == title):
  633. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  634. else:
  635. nosharp = re.sub("<sharp>", "#", results[0])
  636. curs.execute("select title from data where title = ?", [nosharp])
  637. y = curs.fetchall()
  638. if(y):
  639. clas = ''
  640. else:
  641. clas = 'not_thing'
  642. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + re.sub('(?:<a ([^>]*)>|<\/a>)', '', g) + '</a>', data, 1)
  643. backlink_plus(title, results[0], '', num)
  644. else:
  645. break
  646. while(1):
  647. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  648. if(m):
  649. result = m.groups()
  650. end = str(result[0])
  651. while(1):
  652. isspace = re.search("( +)\*\s([^\n]*)", end)
  653. if(isspace):
  654. spacebar = isspace.groups()
  655. up = len(spacebar[0]) * 20
  656. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  657. else:
  658. break
  659. end = re.sub("\n", '', end)
  660. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul style="margin-top: 10px;" id="list">' + end + '</ul>', data, 1)
  661. else:
  662. break
  663. now_time = get_time()
  664. data = re.sub('\[date\]', now_time, data)
  665. time_data = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
  666. time = time_data.groups()
  667. age_data = re.findall('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', data)
  668. for age in age_data:
  669. year = int(time[0]) - int(age[0])
  670. if(age[1] > time[1]):
  671. year -= 1
  672. elif(age[1] == time[1]):
  673. if(age[2] > time[2]):
  674. year -= 1
  675. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
  676. data = re.sub("-{4,11}", "<hr>", data)
  677. while(1):
  678. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  679. if(b):
  680. result = b.groups()
  681. up = re.sub(' ', '<span id="in"></span>', result[1])
  682. if(re.search('<\/h[0-9]>', result[0])):
  683. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  684. else:
  685. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  686. else:
  687. break
  688. a = 1
  689. tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
  690. namu = []
  691. while(1):
  692. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  693. if(b):
  694. results = b.groups()
  695. if(not results[1] and results[0]):
  696. i = 0
  697. while(1):
  698. try:
  699. if(namu[i] == results[0]):
  700. none_this = 0
  701. break
  702. else:
  703. i += 2
  704. except:
  705. none_this = 1
  706. break
  707. if(none_this == 0):
  708. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  709. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  710. </sup> \
  711. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  712. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + namu[i + 1] + " \
  713. </div>", data, 1)
  714. else:
  715. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  716. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  717. </sup>", data, 1)
  718. else:
  719. if(results[0]):
  720. namu += [results[0]]
  721. namu += [results[1]]
  722. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  723. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  724. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  725. </sup> \
  726. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  727. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + results[1] + " \
  728. </div>", data, 1)
  729. else:
  730. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</a> " + results[1] + "</span><br>"
  731. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", '<sup> \
  732. <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');" id="rfn-' + str(a) + '">[' + str(a) + ']</a> \
  733. </sup> \
  734. <div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"> \
  735. <a onclick="folding(' + str(fol_num) + ');" href="#fn-' + str(a) + '">[' + str(a) + ']</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">[X]</a> ' + results[1] + ' \
  736. </div>', data, 1)
  737. a += 1
  738. fol_num += 2
  739. else:
  740. tou += '</div>'
  741. if(tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>"):
  742. tou = ""
  743. break
  744. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  745. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  746. data = re.sub("\[각주\]", "<br>" + tou, data)
  747. data += tou
  748. if(category):
  749. data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
  750. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  751. while(1):
  752. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  753. if(y):
  754. a = y.groups()
  755. mid_data = re.sub("\|\|", "#table#", a[0])
  756. mid_data = re.sub("\r\n", "<br>", mid_data)
  757. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  758. else:
  759. break
  760. data = re.sub("#table#", "||", data)
  761. data = re.sub("<tablenobr>", "\r\n", data)
  762. while(1):
  763. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  764. if(m):
  765. results = m.groups()
  766. table = results[0]
  767. while(1):
  768. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  769. if(a):
  770. row = ''
  771. cel = ''
  772. celstyle = ''
  773. rowstyle = ''
  774. alltable = ''
  775. table_d = ''
  776. result = a.groups()
  777. if(result[1]):
  778. table_d = table_p(result[1], result[0])
  779. alltable = table_d[0]
  780. rowstyle = table_d[1]
  781. celstyle = table_d[2]
  782. row = table_d[3]
  783. cel = table_d[4]
  784. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  785. <tbody> \
  786. <tr " + rowstyle + "> \
  787. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  788. else:
  789. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  790. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  791. <tbody> \
  792. <tr> \
  793. <td " + cel + ">", table, 1)
  794. else:
  795. break
  796. table = re.sub("\|\|$", "</td> \
  797. </tr> \
  798. </tbody> \
  799. </table>", table)
  800. while(1):
  801. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  802. if(b):
  803. row = ''
  804. cel = ''
  805. celstyle = ''
  806. rowstyle = ''
  807. table_d = ''
  808. result = b.groups()
  809. if(result[1]):
  810. table_d = table_p(result[1], result[0])
  811. rowstyle = table_d[1]
  812. celstyle = table_d[2]
  813. row = table_d[3]
  814. cel = table_d[4]
  815. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  816. </tr> \
  817. <tr " + rowstyle + "> \
  818. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  819. else:
  820. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  821. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  822. </tr> \
  823. <tr> \
  824. <td " + cel + ">", table, 1)
  825. else:
  826. break
  827. while(1):
  828. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  829. if(c):
  830. row = ''
  831. cel = ''
  832. celstyle = ''
  833. table_d = ''
  834. result = c.groups()
  835. if(result[1]):
  836. table_d = table_p(result[1], result[0])
  837. celstyle = table_d[2]
  838. row = table_d[3]
  839. cel = table_d[4]
  840. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  841. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  842. else:
  843. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  844. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  845. <td " + cel + ">", table, 1)
  846. else:
  847. break
  848. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  849. else:
  850. break
  851. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  852. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  853. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  854. data = re.sub("<space>", " ", data)
  855. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  856. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  857. data = re.sub('\n', '<br>', data)
  858. data = re.sub('<isbr>', '\r\n', data)
  859. data = re.sub('^(?:<br>|\r|\n| )+', '', data)
  860. data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)
  861. conn.commit()
  862. return(data)