mark.py 43 KB

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