mark.py 42 KB

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