mark.py 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  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"]):
  165. pas_end = p_d[0]
  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):
  295. i = [0, 0, 0, 0, 0, 0, 0]
  296. last = 0
  297. span = ''
  298. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  299. while(1):
  300. i[0] += 1
  301. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
  302. if(m):
  303. result = m.groups()
  304. wiki = len(result[0])
  305. if(last < wiki):
  306. last = wiki
  307. else:
  308. last = wiki
  309. if(wiki == 1):
  310. i[2] = 0
  311. i[3] = 0
  312. i[4] = 0
  313. i[5] = 0
  314. i[6] = 0
  315. elif(wiki == 2):
  316. i[3] = 0
  317. i[4] = 0
  318. i[5] = 0
  319. i[6] = 0
  320. elif(wiki == 3):
  321. i[4] = 0
  322. i[5] = 0
  323. i[6] = 0
  324. elif(wiki == 4):
  325. i[5] = 0
  326. i[6] = 0
  327. elif(wiki == 5):
  328. i[6] = 0
  329. if(wiki == 1):
  330. i[1] += 1
  331. elif(wiki == 2):
  332. i[2] += 1
  333. elif(wiki == 3):
  334. i[3] += 1
  335. elif(wiki == 4):
  336. i[4] += 1
  337. elif(wiki == 5):
  338. i[5] += 1
  339. else:
  340. i[6] += 1
  341. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  342. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  343. toc = re.sub("0\.", '', toc)
  344. toc = re.sub("#\.", '.', toc)
  345. toc = re.sub("\.$", '', toc)
  346. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  347. if(test):
  348. g = test.groups()
  349. if(g[4]):
  350. span = '<span id="out"></span>' * 4
  351. elif(g[3]):
  352. span = '<span id="out"></span>' * 3
  353. elif(g[2]):
  354. span = '<span id="out"></span>' * 2
  355. elif(g[1]):
  356. span = '<span id="out"></span>'
  357. else:
  358. span = ''
  359. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  360. c = re.sub(" $", "", result[1])
  361. d = c
  362. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  363. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '"><a href="#toc" id="s-' + toc + '">' + toc + '.</a> ' + d + ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span></h' + str(wiki) + '>', data, 1)
  364. else:
  365. rtoc += '</div>'
  366. break
  367. data = re.sub("\[목차\]", rtoc, data)
  368. return(data)
  369. def backlink_plus(name, link, backtype, num):
  370. if(num == 1):
  371. curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
  372. y = curs.fetchall()
  373. if(not y):
  374. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  375. def cat_plus(name, link, num):
  376. if(num == 1):
  377. curs.execute("select title from cat where title = ? and cat = ?", [link, name])
  378. y = curs.fetchall()
  379. if(not y):
  380. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  381. def namumark(title, data, num, in_c):
  382. data = html_pas(data)
  383. fol_num = 0
  384. var_d = mid_pas(data, fol_num, 0, in_c)
  385. data = var_d[0]
  386. fol_num = var_d[1]
  387. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  388. data = savemark(data)
  389. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]")
  390. while(1):
  391. m = include.search(data)
  392. if(m):
  393. results = m.groups()
  394. if(results[0] == title):
  395. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  396. else:
  397. curs.execute("select data from data where title = ?", [results[0]])
  398. in_con = curs.fetchall()
  399. backlink_plus(title, results[0], 'include', num)
  400. if(in_con):
  401. in_data = in_con[0][0]
  402. in_data = include.sub("", in_data)
  403. in_data = html_pas(in_data)
  404. var_d = mid_pas(in_data, fol_num, 1, in_c)
  405. in_data = var_d[0]
  406. fol_num = var_d[1]
  407. if(results[1]):
  408. a = results[1]
  409. while(1):
  410. g = re.search("([^= ,]*)\=([^,]*)", a)
  411. if(g):
  412. result = g.groups()
  413. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  414. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  415. else:
  416. break
  417. in_data = toc_pas(in_data, results[0])
  418. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  419. else:
  420. data = include.sub("<a class=\"not_thing\" href=\"" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  421. else:
  422. break
  423. while(1):
  424. m = re.search('^#(?:redirect|넘겨주기) ([^\n]*)$', data)
  425. if(m):
  426. results = m.groups()
  427. g = re.sub("\\\#", "<sharp>", results[0])
  428. aa = re.search("^([^\n]*)(#(?:[^\n]*))$", g)
  429. if(aa):
  430. results = aa.groups()
  431. nosharp = re.sub("<sharp>", "#", results[0])
  432. data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(nosharp) + '/from/' + url_pas(title) + results[1] + '" />', data, 1)
  433. else:
  434. nosharp = re.sub("<sharp>", "#", g)
  435. data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(nosharp) + '/from/' + url_pas(title) + '" />', data, 1)
  436. backlink_plus(title, results[0], 'redirect', num)
  437. else:
  438. break
  439. data = '\n' + data + '\n'
  440. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  441. while(1):
  442. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  443. if(m):
  444. result = m.groups()
  445. blockquote = result[0]
  446. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  447. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  448. else:
  449. break
  450. if(not re.search('\[목차\]', data)):
  451. if(not re.search('\[목차\(없음\)\]', data)):
  452. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  453. else:
  454. data = re.sub("\[목차\(없음\)\]", "", data)
  455. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  456. data = toc_pas(data, title)
  457. category = ''
  458. while(1):
  459. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  460. if(m):
  461. g = m.groups()
  462. if(title != g[0]):
  463. cat_plus(title, g[0], num)
  464. if(category == ''):
  465. curs.execute("select title from data where title = ?", [g[0]])
  466. exists = curs.fetchall()
  467. if(exists):
  468. red = ""
  469. else:
  470. red = 'class="not_thing"'
  471. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  472. else:
  473. curs.execute("select title from data where title = ?", [g[0]])
  474. exists = curs.fetchall()
  475. if(exists):
  476. red = ""
  477. else:
  478. red = 'class="not_thing"'
  479. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  480. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  481. else:
  482. break
  483. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  484. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  485. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)*)(?:~~|--)', '<s>\g<in></s>', data)
  486. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  487. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  488. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  489. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  490. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  491. <tbody> \
  492. <tr> \
  493. <td> \
  494. \g<in> \
  495. </td> \
  496. </tr> \
  497. </tbody> \
  498. </table>', data)
  499. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  500. \g<in> \
  501. <rp>(</rp> \
  502. <rt>\g<out></rt> \
  503. <rp>)</rp> \
  504. </ruby>', data)
  505. data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data)
  506. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  507. if(test):
  508. for wiki in test:
  509. if(wiki[1]):
  510. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  511. else:
  512. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  513. while(1):
  514. m = re.search("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  515. if(m):
  516. img_d = m.groups()
  517. if(img_d):
  518. if(img_d[0] == '파일' and not re.search("^파일:([^\n]*)", title)):
  519. backlink_plus(title, '파일:' + img_d[1], 'file', num)
  520. width = ''
  521. height = ''
  522. if(img_d[2]):
  523. width_r = re.search("width=([^ \n&]*)", img_d[2])
  524. height_r = re.search("height=([^ \n&]*)", img_d[2])
  525. if(width_r):
  526. width_d = width_r.groups()
  527. width = width_d[0]
  528. if(height_r):
  529. height_d = height_r.groups()
  530. height = height_d[0]
  531. if(img_d[0] == '파일'):
  532. img_e = re.search('^(.+)(\.(?:.+))$', img_d[1]).groups()
  533. 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)
  534. else:
  535. data = re.sub("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", '<img src="' + img_d[1] + '" width="' + width + '" height="' + height + '">', data, 1)
  536. else:
  537. break
  538. else:
  539. break
  540. data = re.sub("\[br\]",'<br>', data)
  541. while(1):
  542. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  543. m = com.search(data)
  544. if(m):
  545. src = ''
  546. width = '560'
  547. height = '315'
  548. time = '0'
  549. result = m.groups()
  550. if(result[0]):
  551. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-]*))$', result[0])
  552. if(yudt):
  553. if(yudt.groups()[0]):
  554. src = yudt.groups()[0]
  555. elif(yudt.groups()[1]):
  556. src = yudt.groups()[1]
  557. elif(yudt.groups()[2]):
  558. src = yudt.groups()[2]
  559. else:
  560. src = ''
  561. if(result[1]):
  562. mdata = re.search('width=([0-9]*)', result[1])
  563. if(mdata):
  564. width = mdata.groups()[0]
  565. mdata = re.search('height=([0-9]*)', result[1])
  566. if(mdata):
  567. height = mdata.groups()[0]
  568. mdata = re.search('time=([0-9]*)', result[1])
  569. if(mdata):
  570. time = mdata.groups()[0]
  571. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  572. else:
  573. break
  574. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  575. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  576. for i in a:
  577. b = re.search('(.*)\/', title)
  578. if(b):
  579. m = b.groups()
  580. if(i):
  581. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  582. else:
  583. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  584. else:
  585. if(i):
  586. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  587. else:
  588. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  589. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  590. while(1):
  591. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  592. if(m):
  593. result = m.groups()
  594. rep = result[0]
  595. rep = re.sub("\\\#", "<sharp>", rep)
  596. a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
  597. results = a.groups()
  598. aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
  599. if(results[1]):
  600. g = re.sub("<sharp>", "#", results[1])
  601. else:
  602. g = re.sub("<sharp>", "#", results[0])
  603. results = aa.groups()
  604. if(not results[1]):
  605. sharp = ''
  606. else:
  607. sharp = results[1]
  608. b = re.search("^http(?:s)?:\/\/", results[0])
  609. if(b):
  610. comp = re.compile("(?:\.(?:jpg|png|gif|jpeg))", re.I)
  611. c = comp.search(results[0])
  612. if(c):
  613. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" rel="nofollow" target="_blank" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  614. else:
  615. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" rel="nofollow" target="_blank" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  616. else:
  617. if(results[0] == title):
  618. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  619. else:
  620. nosharp = re.sub("<sharp>", "#", results[0])
  621. curs.execute("select title from data where title = ?", [nosharp])
  622. y = curs.fetchall()
  623. if(y):
  624. clas = ''
  625. else:
  626. clas = 'not_thing'
  627. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + g + '</a>', data, 1)
  628. backlink_plus(title, results[0], '', num)
  629. else:
  630. break
  631. while(1):
  632. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  633. if(m):
  634. result = m.groups()
  635. end = str(result[0])
  636. while(1):
  637. isspace = re.search("( +)\*\s([^\n]*)", end)
  638. if(isspace):
  639. spacebar = isspace.groups()
  640. up = len(spacebar[0]) * 20
  641. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  642. else:
  643. break
  644. end = re.sub("\n", '', end)
  645. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
  646. else:
  647. break
  648. now_time = get_time()
  649. data = re.sub('\[date\]', now_time, data)
  650. time_data = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
  651. time = time_data.groups()
  652. age_data = re.findall('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', data)
  653. for age in age_data:
  654. year = int(time[0]) - int(age[0])
  655. if(age[1] > time[1]):
  656. year -= 1
  657. elif(age[1] == time[1]):
  658. if(age[2] > time[2]):
  659. year -= 1
  660. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
  661. data = re.sub("-{4,11}", "<hr>", data)
  662. while(1):
  663. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  664. if(b):
  665. result = b.groups()
  666. up = re.sub(' ', '<span id="in"></span>', result[1])
  667. if(re.search('<\/h[0-9]>', result[0])):
  668. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  669. else:
  670. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  671. else:
  672. break
  673. a = 1
  674. tou = "<hr id='footnote'><div><br>"
  675. namu = []
  676. while(1):
  677. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  678. if(b):
  679. results = b.groups()
  680. if(not results[1] and results[0]):
  681. i = 0
  682. while(1):
  683. try:
  684. if(namu[i] == results[0]):
  685. none_this = 0
  686. break
  687. else:
  688. i += 2
  689. except:
  690. none_this = 1
  691. break
  692. if(none_this == 0):
  693. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  694. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  695. </sup> \
  696. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  697. <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] + " \
  698. </div>", data, 1)
  699. else:
  700. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  701. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  702. </sup>", data, 1)
  703. else:
  704. if(results[0]):
  705. namu += [results[0]]
  706. namu += [results[1]]
  707. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  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> " + results[1] + " \
  713. </div>", data, 1)
  714. else:
  715. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</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) + '">[' + str(a) + ']</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) + '">[' + str(a) + ']</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">[X]</a> ' + results[1] + ' \
  721. </div>', data, 1)
  722. a += 1
  723. fol_num += 2
  724. else:
  725. tou += '</div>'
  726. if(tou == "<hr id='footnote'><div><br></div>"):
  727. tou = ""
  728. break
  729. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  730. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  731. data = re.sub("\[각주\]", "<br>" + tou, data)
  732. data += tou
  733. if(category):
  734. data += '<div id="cate">분류: ' + category + '</div>'
  735. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  736. while(1):
  737. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  738. if(y):
  739. a = y.groups()
  740. mid_data = re.sub("\|\|", "#table#", a[0])
  741. mid_data = re.sub("\r\n", "<br>", mid_data)
  742. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  743. else:
  744. break
  745. data = re.sub("#table#", "||", data)
  746. data = re.sub("<tablenobr>", "\r\n", data)
  747. while(1):
  748. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  749. if(m):
  750. results = m.groups()
  751. table = results[0]
  752. while(1):
  753. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  754. if(a):
  755. row = ''
  756. cel = ''
  757. celstyle = ''
  758. rowstyle = ''
  759. alltable = ''
  760. table_d = ''
  761. result = a.groups()
  762. if(result[1]):
  763. table_d = table_p(result[1], result[0])
  764. alltable = table_d[0]
  765. rowstyle = table_d[1]
  766. celstyle = table_d[2]
  767. row = table_d[3]
  768. cel = table_d[4]
  769. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  770. <tbody> \
  771. <tr " + rowstyle + "> \
  772. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  773. else:
  774. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  775. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  776. <tbody> \
  777. <tr> \
  778. <td " + cel + ">", table, 1)
  779. else:
  780. break
  781. table = re.sub("\|\|$", "</td> \
  782. </tr> \
  783. </tbody> \
  784. </table>", table)
  785. while(1):
  786. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  787. if(b):
  788. row = ''
  789. cel = ''
  790. celstyle = ''
  791. rowstyle = ''
  792. table_d = ''
  793. result = b.groups()
  794. if(result[1]):
  795. table_d = table_p(result[1], result[0])
  796. rowstyle = table_d[1]
  797. celstyle = table_d[2]
  798. row = table_d[3]
  799. cel = table_d[4]
  800. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  801. </tr> \
  802. <tr " + rowstyle + "> \
  803. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  804. else:
  805. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  806. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  807. </tr> \
  808. <tr> \
  809. <td " + cel + ">", table, 1)
  810. else:
  811. break
  812. while(1):
  813. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  814. if(c):
  815. row = ''
  816. cel = ''
  817. celstyle = ''
  818. table_d = ''
  819. result = c.groups()
  820. if(result[1]):
  821. table_d = table_p(result[1], result[0])
  822. celstyle = table_d[2]
  823. row = table_d[3]
  824. cel = table_d[4]
  825. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  826. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  827. else:
  828. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  829. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  830. <td " + cel + ">", table, 1)
  831. else:
  832. break
  833. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  834. else:
  835. break
  836. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  837. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  838. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  839. data = re.sub("<space>", " ", data)
  840. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  841. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  842. data = re.sub('\n', '<br>', data)
  843. data = re.sub('<isbr>', '\r\n', data)
  844. data = re.sub('^<br>', '', data)
  845. conn.commit()
  846. return(data)