mark.py 43 KB

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