mark.py 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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('%H%', '<', data)
  158. data = re.sub('%\/H%', '>', data)
  159. d_list = re.findall('<(\/)?([^> ]+)( (?:[^>]+)?)?>', data)
  160. for i_list in d_list:
  161. if(i_list[0] == ''):
  162. if(i_list[1] in ['div', 'span', 'embed', 'iframe']):
  163. if(re.search('<\/' + i_list[1] + '>', data)):
  164. src = re.search('src=([^ ]*)', i_list[2])
  165. if(src):
  166. v_src = re.search('https:\/\/([^/\'" ]*)', src.groups()[0])
  167. if(v_src):
  168. if(not v_src.groups()[0] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com"]):
  169. ot = re.sub('src=([^ ]*)', '', i_list[2])
  170. else:
  171. ot = i_list[2]
  172. else:
  173. ot = re.sub('src=([^ ]*)', '', i_list[2])
  174. else:
  175. ot = i_list[2]
  176. po = re.compile('position', re.I)
  177. data = re.sub('<(\/)?([^> ]+)( (?:[^>]+)?)?>', '%H%' + i_list[1] + po.sub('', ot) + '%/H%', data, 1)
  178. data = re.sub('<\/' + i_list[1] + '>', '%H%/' + i_list[1] + '%/H%', data, 1)
  179. data = html.escape(data)
  180. end = re.findall('%H%((?:(?!%/H%).)*)%/H%', data)
  181. for d_end in end:
  182. data = re.sub('%H%((?:(?!%/H%).)*)%/H%', '<' + re.sub('&quot;', '"', re.sub('&#x27;', "'", d_end)) + '>', data, 1)
  183. return(data)
  184. def mid_pas(data, fol_num, include, in_c):
  185. com = re.compile("{{{((?:(?!{{|}}).)*)}}}", re.DOTALL)
  186. while(1):
  187. is_it = com.search(data)
  188. if(is_it):
  189. it_d = is_it.groups()[0]
  190. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  191. big = big_a.search(it_d)
  192. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  193. small = small_a.search(it_d)
  194. color_a = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  195. color = color_a.search(it_d)
  196. color_b = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  197. color_2 = color_b.search(it_d)
  198. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  199. color_3 = color_c.search(it_d)
  200. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  201. back = back_a.search(it_d)
  202. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  203. back_2 = back_b.search(it_d)
  204. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  205. back_3 = back_c.search(it_d)
  206. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  207. include_out = include_out_a.search(it_d)
  208. div_a = re.compile("^#!wiki\sstyle=(?:&quot;|&apos;)((?:(?!&quot;|&apos;).)*)(?:&quot;|&apos;)\r\n(.*)$", re.DOTALL)
  209. div = div_a.search(it_d)
  210. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  211. html = html_a.search(it_d)
  212. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  213. fol = fol_a.search(it_d)
  214. syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
  215. syn = syn_a.search(it_d)
  216. if(big):
  217. big_d = big.groups()
  218. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  219. elif(small):
  220. sm_d = small.groups()
  221. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  222. elif(color):
  223. c_d_1 = color.groups()
  224. data = com.sub('<span style="color: ' + c_d_1[0] + '">' + c_d_1[1] + '</span>', data, 1)
  225. elif(color_2):
  226. c_d_2 = color_2.groups()
  227. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  228. elif(color_3):
  229. c_d_3 = color_3.groups()
  230. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  231. elif(back):
  232. back_d_1 = back.groups()
  233. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  234. elif(back_2):
  235. back_d_2 = back_2.groups()
  236. data = com.sub('<span style="background: #' + back_d_2[0] + '">' + back_d_2[1] + '</span>', data, 1)
  237. elif(back_3):
  238. back_d_3 = back_3.groups()
  239. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  240. elif(div):
  241. div_d = div.groups()
  242. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  243. elif(html):
  244. data = com.sub(html.groups()[0], data, 1)
  245. elif(fol):
  246. fol_d = fol.groups()
  247. data = com.sub( "<div> \
  248. " + fol_d[0] + " \
  249. <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'> \
  250. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>] \
  251. </div> \
  252. <div id='folding_" + str(fol_num + 2) + "' style='display: none;'> \
  253. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>접기</a>] \
  254. </div> \
  255. <div id='folding_" + str(fol_num) + "' style='display: none;'> \
  256. <br> \
  257. " + fol_d[1] + " \
  258. </div> \
  259. </div>", data, 1)
  260. fol_num += 3
  261. elif(syn):
  262. syn_d = syn.groups()
  263. 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)
  264. elif(include_out):
  265. if((include or in_c) == 1):
  266. data = com.sub("", data, 1)
  267. else:
  268. data = com.sub(include_out.groups()[0], data, 1)
  269. else:
  270. data = com.sub('<code>' + it_d + '</code>', data, 1)
  271. else:
  272. break
  273. com = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  274. da_com = com.findall(data)
  275. for com_da in da_com:
  276. mid_data = re.sub("<\/span>", "}}}", com_da)
  277. mid_data = re.sub("<\/div>", "}}}", mid_data)
  278. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  279. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  280. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  281. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  282. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=\"\g<in>\"\n", mid_data)
  283. mid_data = mid_data.replace('<', '&lt;').replace('>', '&gt;')
  284. mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
  285. data = com.sub(mid_data, data, 1)
  286. return([data, fol_num])
  287. def toc_pas(data, title, num):
  288. i = [0, 0, 0, 0, 0, 0, 0]
  289. last = 0
  290. toc_c = -1
  291. toc_d = -1
  292. span = ''
  293. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  294. while(1):
  295. i[0] += 1
  296. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
  297. if(m):
  298. result = m.groups()
  299. wiki = len(result[0])
  300. if(last < wiki):
  301. last = wiki
  302. else:
  303. last = wiki
  304. if(wiki == 1):
  305. i[2] = 0
  306. i[3] = 0
  307. i[4] = 0
  308. i[5] = 0
  309. i[6] = 0
  310. elif(wiki == 2):
  311. i[3] = 0
  312. i[4] = 0
  313. i[5] = 0
  314. i[6] = 0
  315. elif(wiki == 3):
  316. i[4] = 0
  317. i[5] = 0
  318. i[6] = 0
  319. elif(wiki == 4):
  320. i[5] = 0
  321. i[6] = 0
  322. elif(wiki == 5):
  323. i[6] = 0
  324. if(wiki == 1):
  325. i[1] += 1
  326. elif(wiki == 2):
  327. i[2] += 1
  328. elif(wiki == 3):
  329. i[3] += 1
  330. elif(wiki == 4):
  331. i[4] += 1
  332. elif(wiki == 5):
  333. i[5] += 1
  334. else:
  335. i[6] += 1
  336. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  337. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  338. toc = re.sub("0\.", '', toc)
  339. toc = re.sub("#\.", '.', toc)
  340. toc = re.sub("\.$", '', toc)
  341. if(toc_c == -1):
  342. margin = 'style="margin-top: 30px;"'
  343. toc_c = toc.count('.')
  344. else:
  345. toc_d = toc.count('.')
  346. if(toc_c == toc_d):
  347. margin = 'style="margin-top: 30px;"'
  348. else:
  349. if(toc_d < toc_c):
  350. margin = 'style="margin-top: 30px;"'
  351. else:
  352. margin = ''
  353. toc_c = toc_d
  354. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  355. if(test):
  356. g = test.groups()
  357. if(g[4]):
  358. span = '<span style="margin-left: 5px;"></span>' * 4
  359. elif(g[3]):
  360. span = '<span style="margin-left: 5px;"></span>' * 3
  361. elif(g[2]):
  362. span = '<span style="margin-left: 5px;"></span>' * 2
  363. elif(g[1]):
  364. span = '<span style="margin-left: 5px;"></span>'
  365. else:
  366. span = ''
  367. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  368. c = re.sub(" $", "", result[1])
  369. d = c
  370. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  371. edit_d = ''
  372. if(num != 0):
  373. edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
  374. 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)
  375. else:
  376. rtoc += '</div>'
  377. break
  378. data = re.sub("\[목차\]", rtoc, data)
  379. return(data)
  380. def backlink_plus(name, link, backtype, num):
  381. if(num == 1):
  382. curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
  383. y = curs.fetchall()
  384. if(not y):
  385. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  386. def cat_plus(name, link, num):
  387. if(num == 1):
  388. curs.execute("select title from cat where title = ? and cat = ?", [link, name])
  389. y = curs.fetchall()
  390. if(not y):
  391. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  392. def namumark(title, data, num, in_c):
  393. data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
  394. data = html_pas(data)
  395. data = '\r\n' + data + '\r\n'
  396. fol_num = 0
  397. var_d = mid_pas(data, fol_num, 0, in_c)
  398. data = var_d[0]
  399. fol_num = var_d[1]
  400. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
  401. while(1):
  402. m = include.search(data)
  403. if(m):
  404. results = m.groups()
  405. if(results[0] == title):
  406. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  407. else:
  408. curs.execute("select data from data where title = ?", [results[0]])
  409. in_con = curs.fetchall()
  410. backlink_plus(title, results[0], 'include', num)
  411. if(in_con):
  412. in_data = in_con[0][0]
  413. in_data = include.sub("", in_data)
  414. in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
  415. in_data = html_pas(in_data)
  416. var_d = mid_pas(in_data, fol_num, 1, in_c)
  417. in_data = var_d[0]
  418. fol_num = var_d[1]
  419. if(results[1]):
  420. a = results[1]
  421. while(1):
  422. g = re.search("([^= ,]*)\=([^,]*)", a)
  423. if(g):
  424. result = g.groups()
  425. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  426. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  427. else:
  428. break
  429. in_data = toc_pas(in_data, results[0], num)
  430. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  431. else:
  432. data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  433. else:
  434. break
  435. data = re.sub("##\s?([^\n]*)\r\n", "", data)
  436. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  437. data = savemark(data)
  438. while(1):
  439. r_data = re.search('\n#(?:redirect|넘겨주기) ([^\n]*)', data)
  440. if(r_data):
  441. n_data = r_data.groups()
  442. n_s_data = re.sub("\\\#", "<sharp>", n_data[0])
  443. s_data = re.search("^([^\n#]*)(#(?:[^\n]*))?$", n_s_data)
  444. r_s_data = s_data.groups()
  445. n_sharp = re.sub("<sharp>", "#", r_s_data[0])
  446. if(r_s_data[1]):
  447. plus = r_s_data[1]
  448. else:
  449. plus = ''
  450. data = re.sub('\n#(?:redirect|넘겨주기) ([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + re.sub('%0D$', '', url_pas(n_sharp)) + '/from/' + url_pas(title) + plus + '" />', data, 1)
  451. backlink_plus(title, n_data[0], 'redirect', num)
  452. else:
  453. break
  454. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  455. while(1):
  456. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  457. if(m):
  458. result = m.groups()
  459. blockquote = result[0]
  460. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  461. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  462. else:
  463. break
  464. if(not re.search('\[목차\]', data)):
  465. if(not re.search('\[목차\(없음\)\]', data)):
  466. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  467. else:
  468. data = re.sub("\[목차\(없음\)\]", "", data)
  469. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  470. data = toc_pas(data, title, num)
  471. category = ''
  472. while(1):
  473. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  474. if(m):
  475. g = m.groups()
  476. if(title != g[0]):
  477. cat_plus(title, g[0], num)
  478. if(category == ''):
  479. curs.execute("select title from data where title = ?", [g[0]])
  480. exists = curs.fetchall()
  481. if(exists):
  482. red = ""
  483. else:
  484. red = 'class="not_thing"'
  485. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  486. else:
  487. curs.execute("select title from data where title = ?", [g[0]])
  488. exists = curs.fetchall()
  489. if(exists):
  490. red = ""
  491. else:
  492. red = 'class="not_thing"'
  493. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  494. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  495. else:
  496. break
  497. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  498. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  499. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)+)(?:~~|--)', '<s>\g<in></s>', data)
  500. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  501. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  502. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  503. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  504. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  505. <tbody> \
  506. <tr> \
  507. <td> \
  508. \g<in> \
  509. </td> \
  510. </tr> \
  511. </tbody> \
  512. </table>', data)
  513. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  514. \g<in> \
  515. <rp>(</rp> \
  516. <rt>\g<out></rt> \
  517. <rp>)</rp> \
  518. </ruby>', data)
  519. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  520. if(test):
  521. for wiki in test:
  522. if(wiki[1]):
  523. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  524. else:
  525. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  526. while(1):
  527. m = re.search("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  528. if(m):
  529. img_d = m.groups()
  530. if(img_d):
  531. if(img_d[0] == '파일' and not re.search("^파일:([^\n]*)", title)):
  532. backlink_plus(title, '파일:' + img_d[1], 'file', num)
  533. width = ''
  534. height = ''
  535. if(img_d[2]):
  536. width_r = re.search("width=([^ \n&]*)", img_d[2])
  537. height_r = re.search("height=([^ \n&]*)", img_d[2])
  538. if(width_r):
  539. width_d = width_r.groups()
  540. width = width_d[0]
  541. if(height_r):
  542. height_d = height_r.groups()
  543. height = height_d[0]
  544. if(img_d[0] == '파일'):
  545. img_e = re.search('^(.+)(\.(?:.+))$', img_d[1]).groups()
  546. 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)
  547. else:
  548. data = re.sub("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", '<img src="' + img_d[1] + '" width="' + width + '" height="' + height + '">', data, 1)
  549. else:
  550. break
  551. else:
  552. break
  553. data = re.sub("\[br\]",'<br>', data)
  554. while(1):
  555. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  556. m = com.search(data)
  557. if(m):
  558. src = ''
  559. width = '560'
  560. height = '315'
  561. time = '0'
  562. result = m.groups()
  563. if(result[0]):
  564. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
  565. if(yudt):
  566. if(yudt.groups()[0]):
  567. src = yudt.groups()[0]
  568. elif(yudt.groups()[1]):
  569. src = yudt.groups()[1]
  570. elif(yudt.groups()[2]):
  571. src = yudt.groups()[2]
  572. else:
  573. src = ''
  574. if(result[1]):
  575. mdata = re.search('width=([0-9%]*)', result[1])
  576. if(mdata):
  577. width = mdata.groups()[0]
  578. mdata = re.search('height=([0-9%]*)', result[1])
  579. if(mdata):
  580. height = mdata.groups()[0]
  581. mdata = re.search('time=([0-9]*)', result[1])
  582. if(mdata):
  583. time = mdata.groups()[0]
  584. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  585. else:
  586. break
  587. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  588. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  589. for i in a:
  590. b = re.search('(.*)\/', title)
  591. if(b):
  592. m = b.groups()
  593. if(i):
  594. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  595. else:
  596. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  597. else:
  598. if(i):
  599. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  600. else:
  601. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  602. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  603. while(1):
  604. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  605. if(m):
  606. result = m.groups()
  607. rep = result[0]
  608. rep = re.sub("\\\#", "<sharp>", rep)
  609. a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
  610. results = a.groups()
  611. aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
  612. if(results[1]):
  613. g = re.sub("<sharp>", "#", results[1])
  614. else:
  615. g = re.sub("<sharp>", "#", results[0])
  616. results = aa.groups()
  617. if(not results[1]):
  618. sharp = ''
  619. else:
  620. sharp = results[1]
  621. b = re.search("^http(?:s)?:\/\/", results[0])
  622. if(b):
  623. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" rel="nofollow" target="_blank" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  624. else:
  625. if(results[0] == title):
  626. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  627. else:
  628. nosharp = re.sub("<sharp>", "#", results[0])
  629. curs.execute("select title from data where title = ?", [nosharp])
  630. y = curs.fetchall()
  631. if(y):
  632. clas = ''
  633. else:
  634. clas = 'not_thing'
  635. 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)
  636. backlink_plus(title, results[0], '', num)
  637. else:
  638. break
  639. while(1):
  640. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  641. if(m):
  642. result = m.groups()
  643. end = str(result[0])
  644. while(1):
  645. isspace = re.search("( +)\*\s([^\n]*)", end)
  646. if(isspace):
  647. spacebar = isspace.groups()
  648. up = len(spacebar[0]) * 20
  649. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  650. else:
  651. break
  652. end = re.sub("\n", '', end)
  653. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul style="margin-top: 10px;" id="list">' + end + '</ul>', data, 1)
  654. else:
  655. break
  656. now_time = get_time()
  657. data = re.sub('\[date\]', now_time, data)
  658. time_data = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
  659. time = time_data.groups()
  660. age_data = re.findall('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', data)
  661. for age in age_data:
  662. year = int(time[0]) - int(age[0])
  663. if(age[1] > time[1]):
  664. year -= 1
  665. elif(age[1] == time[1]):
  666. if(age[2] > time[2]):
  667. year -= 1
  668. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
  669. data = re.sub("-{4,11}", "<hr>", data)
  670. while(1):
  671. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  672. if(b):
  673. result = b.groups()
  674. up = re.sub(' ', '<span id="in"></span>', result[1])
  675. if(re.search('<\/h[0-9]>', result[0])):
  676. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  677. else:
  678. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  679. else:
  680. break
  681. a = 1
  682. tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
  683. namu = []
  684. while(1):
  685. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  686. if(b):
  687. results = b.groups()
  688. if(not results[1] and results[0]):
  689. i = 0
  690. while(1):
  691. try:
  692. if(namu[i] == results[0]):
  693. none_this = 0
  694. break
  695. else:
  696. i += 2
  697. except:
  698. none_this = 1
  699. break
  700. if(none_this == 0):
  701. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  702. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  703. </sup> \
  704. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  705. <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] + " \
  706. </div>", data, 1)
  707. else:
  708. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  709. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  710. </sup>", data, 1)
  711. else:
  712. if(results[0]):
  713. namu += [results[0]]
  714. namu += [results[1]]
  715. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  716. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  717. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  718. </sup> \
  719. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  720. <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] + " \
  721. </div>", data, 1)
  722. else:
  723. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</a> " + results[1] + "</span><br>"
  724. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", '<sup> \
  725. <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');" id="rfn-' + str(a) + '">[' + str(a) + ']</a> \
  726. </sup> \
  727. <div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"> \
  728. <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] + ' \
  729. </div>', data, 1)
  730. a += 1
  731. fol_num += 2
  732. else:
  733. tou += '</div>'
  734. if(tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>"):
  735. tou = ""
  736. break
  737. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  738. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  739. data = re.sub("\[각주\]", "<br>" + tou, data)
  740. data += tou
  741. if(category):
  742. data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
  743. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  744. while(1):
  745. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  746. if(y):
  747. a = y.groups()
  748. mid_data = re.sub("\|\|", "#table#", a[0])
  749. mid_data = re.sub("\r\n", "<br>", mid_data)
  750. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  751. else:
  752. break
  753. data = re.sub("#table#", "||", data)
  754. data = re.sub("<tablenobr>", "\r\n", data)
  755. while(1):
  756. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  757. if(m):
  758. results = m.groups()
  759. table = results[0]
  760. while(1):
  761. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  762. if(a):
  763. row = ''
  764. cel = ''
  765. celstyle = ''
  766. rowstyle = ''
  767. alltable = ''
  768. table_d = ''
  769. result = a.groups()
  770. if(result[1]):
  771. table_d = table_p(result[1], result[0])
  772. alltable = table_d[0]
  773. rowstyle = table_d[1]
  774. celstyle = table_d[2]
  775. row = table_d[3]
  776. cel = table_d[4]
  777. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  778. <tbody> \
  779. <tr " + rowstyle + "> \
  780. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  781. else:
  782. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  783. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  784. <tbody> \
  785. <tr> \
  786. <td " + cel + ">", table, 1)
  787. else:
  788. break
  789. table = re.sub("\|\|$", "</td> \
  790. </tr> \
  791. </tbody> \
  792. </table>", table)
  793. while(1):
  794. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  795. if(b):
  796. row = ''
  797. cel = ''
  798. celstyle = ''
  799. rowstyle = ''
  800. table_d = ''
  801. result = b.groups()
  802. if(result[1]):
  803. table_d = table_p(result[1], result[0])
  804. rowstyle = table_d[1]
  805. celstyle = table_d[2]
  806. row = table_d[3]
  807. cel = table_d[4]
  808. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  809. </tr> \
  810. <tr " + rowstyle + "> \
  811. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  812. else:
  813. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  814. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  815. </tr> \
  816. <tr> \
  817. <td " + cel + ">", table, 1)
  818. else:
  819. break
  820. while(1):
  821. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  822. if(c):
  823. row = ''
  824. cel = ''
  825. celstyle = ''
  826. table_d = ''
  827. result = c.groups()
  828. if(result[1]):
  829. table_d = table_p(result[1], result[0])
  830. celstyle = table_d[2]
  831. row = table_d[3]
  832. cel = table_d[4]
  833. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  834. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  835. else:
  836. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  837. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  838. <td " + cel + ">", table, 1)
  839. else:
  840. break
  841. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  842. else:
  843. break
  844. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  845. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  846. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  847. data = re.sub("<space>", " ", data)
  848. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  849. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  850. data = re.sub('\n', '<br>', data)
  851. data = re.sub('<isbr>', '\r\n', data)
  852. data = re.sub('^(?:<br>|\r|\n| )+', '', data)
  853. data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)
  854. conn.commit()
  855. return(data)