mark.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. import datetime
  11. json_data = open('set.json').read()
  12. set_data = json.loads(json_data)
  13. conn = sqlite3.connect(set_data['db'] + '.db')
  14. curs = conn.cursor()
  15. session_opts = {
  16. 'session.type': 'file',
  17. 'session.data_dir': './app_session/',
  18. 'session.auto': 1
  19. }
  20. app = beaker.middleware.SessionMiddleware(app(), session_opts)
  21. def get_time():
  22. now = time.localtime()
  23. 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)
  24. return(date)
  25. def ip_check():
  26. session = request.environ.get('beaker.session')
  27. if(session.get('Now') == 1):
  28. ip = format(session['DREAMER'])
  29. else:
  30. if(request.environ.get('HTTP_X_FORWARDED_FOR')):
  31. ip = request.environ.get('HTTP_X_FORWARDED_FOR')
  32. else:
  33. ip = request.environ.get('REMOTE_ADDR')
  34. return(ip)
  35. def url_pas(data):
  36. return(parse.quote(data).replace('/','%2F'))
  37. def sha224(data):
  38. return(hashlib.sha224(bytes(data, 'utf-8')).hexdigest())
  39. def savemark(data):
  40. data = re.sub("\[date\(now\)\]", get_time(), data)
  41. if(not re.search("\.", ip_check())):
  42. name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
  43. else:
  44. name = ip_check()
  45. data = re.sub("\[name\]", name, data)
  46. return(data)
  47. def send_p(d):
  48. d = html.escape(d)
  49. js_p = re.compile('javascript:', re.I)
  50. d = js_p.sub('', d)
  51. d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)
  52. return(d)
  53. def table_p(d, d2):
  54. alltable = 'style="'
  55. celstyle = 'style="'
  56. rowstyle = 'style="'
  57. row = ''
  58. cel = ''
  59. table_w = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", d)
  60. table_h = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", d)
  61. table_a = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", d)
  62. if(table_w):
  63. alltable += 'width: ' + table_w.groups()[0] + ';'
  64. if(table_h):
  65. alltable += 'height: ' + table_h.groups()[0] + ';'
  66. if(table_a):
  67. if(table_a.groups()[0] == 'right'):
  68. alltable += 'float: right;'
  69. elif(table_a.groups()[0] == 'center'):
  70. alltable += 'margin: auto;'
  71. table_t_a = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  72. if(table_t_a):
  73. if(table_t_a.groups()[0] == 'right'):
  74. alltable += 'text-align: right;'
  75. elif(table_t_a.groups()[0] == 'center'):
  76. alltable += 'text-align: center;'
  77. row_t_a = re.search("&lt;row\s?textalign=((?:(?!&gt;).)*)&gt;", d)
  78. if(row_t_a):
  79. if(row_t_a.groups()[0] == 'right'):
  80. rowstyle += 'text-align: right;'
  81. elif(row_t_a.groups()[0] == 'center'):
  82. rowstyle += 'text-align: center;'
  83. else:
  84. rowstyle += 'text-align: left;'
  85. table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", d)
  86. if(table_cel):
  87. cel = 'colspan="' + table_cel.groups()[0] + '"'
  88. else:
  89. cel = 'colspan="' + str(round(len(d2) / 2)) + '"'
  90. table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", d)
  91. if(table_row):
  92. row = 'rowspan="' + table_row.groups()[0] + '"'
  93. row_bgcolor_2 = re.search("&lt;rowbgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  94. row_bgcolor_3 = re.search("&lt;rowbgcolor=(\w+)&gt;", d)
  95. if(row_bgcolor_2):
  96. rowstyle += 'background: ' + row_bgcolor_2.groups()[0] + ';'
  97. elif(row_bgcolor_3):
  98. rowstyle += 'background: ' + row_bgcolor_3.groups()[0] + ';'
  99. table_border_2 = re.search("&lt;table\s?bordercolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  100. table_border_3 = re.search("&lt;table\s?bordercolor=(\w+)&gt;", d)
  101. if(table_border_2):
  102. alltable += 'border: ' + table_border_2.groups()[0] + ' 2px solid;'
  103. elif(table_border_3):
  104. alltable += 'border: ' + table_border_3.groups()[0] + ' 2px solid;'
  105. table_bgcolor_2 = re.search("&lt;table\s?bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  106. table_bgcolor_3 = re.search("&lt;table\s?bgcolor=(\w+)&gt;", d)
  107. if(table_bgcolor_2):
  108. alltable += 'background: ' + table_bgcolor_2.groups()[0] + ';'
  109. elif(table_bgcolor_3):
  110. alltable += 'background: ' + table_bgcolor_3.groups()[0] + ';'
  111. bgcolor_2 = re.search("&lt;bgcolor=(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  112. bgcolor_3 = re.search("&lt;bgcolor=(\w+)&gt;", d)
  113. if(bgcolor_2):
  114. celstyle += 'background: ' + bgcolor_2.groups()[0] + ';'
  115. elif(bgcolor_3):
  116. celstyle += 'background: ' + bgcolor_3.groups()[0] + ';'
  117. st_bgcolor_2 = re.search("&lt;(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))&gt;", d)
  118. st_bgcolor_3 = re.search("&lt;(\w+)&gt;", d)
  119. if(st_bgcolor_2):
  120. celstyle += 'background: ' + st_bgcolor_2.groups()[0] + ';'
  121. elif(st_bgcolor_3):
  122. celstyle += 'background: ' + st_bgcolor_3.groups()[0] + ';'
  123. n_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", d)
  124. n_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", d)
  125. if(n_width):
  126. celstyle += 'width: ' + n_width.groups()[0] + ';'
  127. if(n_height):
  128. celstyle += 'height: ' + n_height.groups()[0] + ';'
  129. text_right = re.search("&lt;\)&gt;", d)
  130. text_center = re.search("&lt;:&gt;", d)
  131. text_left = re.search("&lt;\(&gt;", d)
  132. if(text_right):
  133. celstyle += 'text-align: right;'
  134. elif(text_center):
  135. celstyle += 'text-align: center;'
  136. elif(text_left):
  137. celstyle += 'text-align: left;'
  138. alltable += '"'
  139. celstyle += '"'
  140. rowstyle += '"'
  141. return([alltable, rowstyle, celstyle, row, cel])
  142. def html_pas(data):
  143. data = re.sub('%H%', '<', data)
  144. data = re.sub('%\/H%', '>', data)
  145. d_list = re.findall('<(\/)?([^> ]+)( (?:[^>]+)?)?>', data)
  146. for i_list in d_list:
  147. if(i_list[0] == ''):
  148. if(i_list[1] in ['div', 'span', 'embed', 'iframe']):
  149. if(re.search('<\/' + i_list[1] + '>', data)):
  150. src = re.search('src=([^ ]*)', i_list[2])
  151. if(src):
  152. v_src = re.search('https:\/\/([^/\'" ]*)', src.groups()[0])
  153. if(v_src):
  154. if(not v_src.groups()[0] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com"]):
  155. ot = re.sub('src=([^ ]*)', '', i_list[2])
  156. else:
  157. ot = i_list[2]
  158. else:
  159. ot = re.sub('src=([^ ]*)', '', i_list[2])
  160. else:
  161. ot = i_list[2]
  162. po = re.compile('position', re.I)
  163. data = re.sub('<(\/)?([^> ]+)( (?:[^>]+)?)?>', '%H%' + i_list[1] + po.sub('', ot) + '%/H%', data, 1)
  164. data = re.sub('<\/' + i_list[1] + '>', '%H%/' + i_list[1] + '%/H%', data, 1)
  165. data = html.escape(data)
  166. end = re.findall('%H%((?:(?!%/H%).)*)%/H%', data)
  167. for d_end in end:
  168. data = re.sub('%H%((?:(?!%/H%).)*)%/H%', '<' + re.sub('&quot;', '"', re.sub('&#x27;', "'", d_end)) + '>', data, 1)
  169. return(data)
  170. def mid_pas(data, fol_num, include, in_c):
  171. com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL)
  172. while(1):
  173. is_it = com.search(data)
  174. if(is_it):
  175. it_d = is_it.groups()[0]
  176. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  177. big = big_a.search(it_d)
  178. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  179. small = small_a.search(it_d)
  180. color_b = re.compile("^(#(?:[0-9a-f-A-F]{6}|[0-9a-f-A-F]{3}))\s(.*)$", re.DOTALL)
  181. color_2 = color_b.search(it_d)
  182. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  183. color_3 = color_c.search(it_d)
  184. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  185. back = back_a.search(it_d)
  186. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  187. back_2 = back_b.search(it_d)
  188. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  189. back_3 = back_c.search(it_d)
  190. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  191. include_out = include_out_a.search(it_d)
  192. div_a = re.compile("^#!wiki\sstyle=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\r\n(.*)$", re.DOTALL)
  193. div = div_a.search(it_d)
  194. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  195. html = html_a.search(it_d)
  196. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  197. fol = fol_a.search(it_d)
  198. syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
  199. syn = syn_a.search(it_d)
  200. if(big):
  201. big_d = big.groups()
  202. data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
  203. elif(small):
  204. sm_d = small.groups()
  205. data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
  206. elif(color_2):
  207. c_d_2 = color_2.groups()
  208. data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
  209. elif(color_3):
  210. c_d_3 = color_3.groups()
  211. data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
  212. elif(back):
  213. back_d_1 = back.groups()
  214. data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
  215. elif(back_2):
  216. back_d_2 = back_2.groups()
  217. data = com.sub('<span style="background: #' + back_d_2[0] + '">' + back_d_2[1] + '</span>', data, 1)
  218. elif(back_3):
  219. back_d_3 = back_3.groups()
  220. data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
  221. elif(div):
  222. div_d = div.groups()
  223. data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
  224. elif(html):
  225. data = com.sub(html.groups()[0], data, 1)
  226. elif(fol):
  227. fol_d = fol.groups()
  228. data = com.sub( "<div> \
  229. " + fol_d[0] + " \
  230. <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'> \
  231. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>] \
  232. </div> \
  233. <div id='folding_" + str(fol_num + 2) + "' style='display: none;'> \
  234. [<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>접기</a>] \
  235. </div> \
  236. <div id='folding_" + str(fol_num) + "' style='display: none;'> \
  237. <br> \
  238. " + fol_d[1] + " \
  239. </div> \
  240. </div>", data, 1)
  241. fol_num += 3
  242. elif(syn):
  243. syn_d = syn.groups()
  244. data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '">' + re.sub('\r\n', '<isbr>', re.sub(' ', '<space>', syn_d[1])) + '</code></pre>', data, 1)
  245. elif(include_out):
  246. if((include or in_c) == 1):
  247. data = com.sub("", data, 1)
  248. else:
  249. data = com.sub(include_out.groups()[0], data, 1)
  250. else:
  251. data = com.sub('<code>' + it_d + '</code>', data, 1)
  252. else:
  253. break
  254. com = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
  255. da_com = com.findall(data)
  256. for com_da in da_com:
  257. mid_data = re.sub("<\/span>", "}}}", com_da)
  258. mid_data = re.sub("<\/div>", "}}}", mid_data)
  259. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  260. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  261. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  262. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  263. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=\"\g<in>\"\n", mid_data)
  264. mid_data = mid_data.replace('<', '&lt;').replace('>', '&gt;')
  265. mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
  266. data = com.sub(mid_data, data, 1)
  267. return([data, fol_num])
  268. def toc_pas(data, title, num):
  269. i = [0, 0, 0, 0, 0, 0, 0]
  270. last = 0
  271. toc_c = -1
  272. toc_d = -1
  273. span = ''
  274. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  275. while(1):
  276. i[0] += 1
  277. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
  278. if(m):
  279. result = m.groups()
  280. wiki = len(result[0])
  281. if(last < wiki):
  282. last = wiki
  283. else:
  284. last = wiki
  285. if(wiki == 1):
  286. i[2] = 0
  287. i[3] = 0
  288. i[4] = 0
  289. i[5] = 0
  290. i[6] = 0
  291. elif(wiki == 2):
  292. i[3] = 0
  293. i[4] = 0
  294. i[5] = 0
  295. i[6] = 0
  296. elif(wiki == 3):
  297. i[4] = 0
  298. i[5] = 0
  299. i[6] = 0
  300. elif(wiki == 4):
  301. i[5] = 0
  302. i[6] = 0
  303. elif(wiki == 5):
  304. i[6] = 0
  305. if(wiki == 1):
  306. i[1] += 1
  307. elif(wiki == 2):
  308. i[2] += 1
  309. elif(wiki == 3):
  310. i[3] += 1
  311. elif(wiki == 4):
  312. i[4] += 1
  313. elif(wiki == 5):
  314. i[5] += 1
  315. else:
  316. i[6] += 1
  317. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  318. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  319. toc = re.sub("0\.", '', toc)
  320. toc = re.sub("#\.", '.', toc)
  321. toc = re.sub("\.$", '', toc)
  322. if(toc_c == -1):
  323. margin = 'style="margin-top: 30px;"'
  324. toc_c = toc.count('.')
  325. else:
  326. toc_d = toc.count('.')
  327. if(toc_c == toc_d):
  328. margin = 'style="margin-top: 30px;"'
  329. else:
  330. if(toc_d < toc_c):
  331. margin = 'style="margin-top: 30px;"'
  332. else:
  333. margin = ''
  334. toc_c = toc_d
  335. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  336. if(test):
  337. g = test.groups()
  338. if(g[4]):
  339. span = '<span style="margin-left: 5px;"></span>' * 4
  340. elif(g[3]):
  341. span = '<span style="margin-left: 5px;"></span>' * 3
  342. elif(g[2]):
  343. span = '<span style="margin-left: 5px;"></span>' * 2
  344. elif(g[1]):
  345. span = '<span style="margin-left: 5px;"></span>'
  346. else:
  347. span = ''
  348. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  349. c = re.sub(" $", "", result[1])
  350. d = c
  351. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  352. edit_d = ''
  353. if(num != 0):
  354. edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
  355. data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' + toc + '.<span style="margin-left: 5px;"></span></a> ' + d + edit_d + '</h' + str(wiki) + '><hr style="margin-top: -5px;">', data, 1)
  356. else:
  357. rtoc += '</div>'
  358. break
  359. data = re.sub("\[목차\]", rtoc, data)
  360. return(data)
  361. def backlink_plus(name, link, backtype, num):
  362. if(num == 1):
  363. curs.execute("delete from back where title = ? and link = ? and type = ?", [link, name, backtype])
  364. curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
  365. def cat_plus(name, link, num):
  366. if(num == 1):
  367. curs.execute("delete from cat where title = ? and cat = ?", [link, name])
  368. curs.execute("insert into cat (title, cat) values (?, ?)", [link, name])
  369. def namumark(title, data, num, in_c):
  370. data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
  371. data = html_pas(data)
  372. data = '\r\n' + data + '\r\n'
  373. fol_num = 0
  374. var_d = mid_pas(data, fol_num, 0, in_c)
  375. data = var_d[0]
  376. fol_num = var_d[1]
  377. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
  378. while(1):
  379. m = include.search(data)
  380. if(m):
  381. results = m.groups()
  382. if(results[0] == title):
  383. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  384. else:
  385. curs.execute("select data from data where title = ?", [results[0]])
  386. in_con = curs.fetchall()
  387. backlink_plus(title, results[0], 'include', num)
  388. if(in_con):
  389. in_data = in_con[0][0]
  390. in_data = include.sub("", in_data)
  391. in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
  392. in_data = html_pas(in_data)
  393. var_d = mid_pas(in_data, fol_num, 1, in_c)
  394. in_data = var_d[0]
  395. fol_num = var_d[1]
  396. if(results[1]):
  397. a = results[1]
  398. while(1):
  399. g = re.search("([^= ,]*)\=([^,]*)", a)
  400. if(g):
  401. result = g.groups()
  402. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  403. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  404. else:
  405. break
  406. in_data = toc_pas(in_data, results[0], num)
  407. data = include.sub('\n<nobr><a href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
  408. else:
  409. data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  410. else:
  411. break
  412. data = re.sub("##\s?([^\n]*)\r\n", "", data)
  413. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  414. data = savemark(data)
  415. while(1):
  416. r_data = re.search('\n#(?:redirect|넘겨주기) ([^\n]*)', data)
  417. if(r_data):
  418. n_data = r_data.groups()
  419. n_s_data = re.sub("\\\#", "<sharp>", n_data[0])
  420. s_data = re.search("^([^\n#]*)(#(?:[^\n]*))?$", n_s_data)
  421. r_s_data = s_data.groups()
  422. n_sharp = re.sub("<sharp>", "#", r_s_data[0])
  423. if(r_s_data[1]):
  424. plus = r_s_data[1]
  425. else:
  426. plus = ''
  427. data = re.sub('\n#(?:redirect|넘겨주기) ([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + re.sub('%0D$', '', url_pas(n_sharp)) + '/from/' + url_pas(title) + plus + '" />', data, 1)
  428. backlink_plus(title, n_data[0], 'redirect', num)
  429. else:
  430. break
  431. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  432. while(1):
  433. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  434. if(m):
  435. result = m.groups()
  436. blockquote = result[0]
  437. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  438. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  439. else:
  440. break
  441. if(not re.search('\[목차\]', data)):
  442. if(not re.search('\[목차\(없음\)\]', data)):
  443. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  444. else:
  445. data = re.sub("\[목차\(없음\)\]", "", data)
  446. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  447. data = toc_pas(data, title, num)
  448. category = ''
  449. while(1):
  450. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  451. if(m):
  452. g = m.groups()
  453. if(title != g[0]):
  454. cat_plus(title, g[0], num)
  455. if(category == ''):
  456. curs.execute("select title from data where title = ?", [g[0]])
  457. exists = curs.fetchall()
  458. if(exists):
  459. red = ""
  460. else:
  461. red = 'class="not_thing"'
  462. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  463. else:
  464. curs.execute("select title from data where title = ?", [g[0]])
  465. exists = curs.fetchall()
  466. if(exists):
  467. red = ""
  468. else:
  469. red = 'class="not_thing"'
  470. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  471. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  472. else:
  473. break
  474. data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
  475. data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', data)
  476. data = re.sub('(?:~~|--)(?P<in>(?:(?!~~|--).)+)(?:~~|--)', '<s>\g<in></s>', data)
  477. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  478. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  479. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  480. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  481. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table> \
  482. <tbody> \
  483. <tr> \
  484. <td> \
  485. \g<in> \
  486. </td> \
  487. </tr> \
  488. </tbody> \
  489. </table>', data)
  490. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby> \
  491. \g<in> \
  492. <rp>(</rp> \
  493. <rt>\g<out></rt> \
  494. <rp>)</rp> \
  495. </ruby>', data)
  496. test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
  497. if(test):
  498. for wiki in test:
  499. if(wiki[1]):
  500. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
  501. else:
  502. data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</a>', data, 1)
  503. while(1):
  504. m = re.search("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  505. if(m):
  506. img_d = m.groups()
  507. if(img_d):
  508. if(img_d[0] == '파일' and not re.search("^파일:([^\n]*)", title)):
  509. backlink_plus(title, '파일:' + img_d[1], 'file', num)
  510. width = ''
  511. height = ''
  512. if(img_d[2]):
  513. width_r = re.search("width=([^ \n&]*)", img_d[2])
  514. height_r = re.search("height=([^ \n&]*)", img_d[2])
  515. if(width_r):
  516. width_d = width_r.groups()
  517. width = width_d[0]
  518. if(height_r):
  519. height_d = height_r.groups()
  520. height = height_d[0]
  521. if(img_d[0] == '파일'):
  522. img_e = re.search('^(.+)(\.(?:.+))$', img_d[1]).groups()
  523. 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)
  524. else:
  525. data = re.sub("\[\[(파일|외부):((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", '<img src="' + img_d[1] + '" width="' + width + '" height="' + height + '">', data, 1)
  526. else:
  527. break
  528. else:
  529. break
  530. data = re.sub("\[br\]",'<br>', data)
  531. while(1):
  532. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  533. m = com.search(data)
  534. if(m):
  535. src = ''
  536. width = '560'
  537. height = '315'
  538. time = '0'
  539. result = m.groups()
  540. if(result[0]):
  541. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
  542. if(yudt):
  543. if(yudt.groups()[0]):
  544. src = yudt.groups()[0]
  545. elif(yudt.groups()[1]):
  546. src = yudt.groups()[1]
  547. elif(yudt.groups()[2]):
  548. src = yudt.groups()[2]
  549. else:
  550. src = ''
  551. if(result[1]):
  552. mdata = re.search('width=([0-9%]*)', result[1])
  553. if(mdata):
  554. width = mdata.groups()[0]
  555. mdata = re.search('height=([0-9%]*)', result[1])
  556. if(mdata):
  557. height = mdata.groups()[0]
  558. mdata = re.search('time=([0-9]*)', result[1])
  559. if(mdata):
  560. time = mdata.groups()[0]
  561. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  562. else:
  563. break
  564. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  565. a = re.findall('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', data)
  566. for i in a:
  567. b = re.search('(.*)\/', title)
  568. if(b):
  569. m = b.groups()
  570. if(i):
  571. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + i + ']]', data, 1)
  572. else:
  573. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + m[0] + ']]', data, 1)
  574. else:
  575. if(i):
  576. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + i + ']]', data, 1)
  577. else:
  578. data = re.sub('\[\[\.\.\/(\|(?:[^\]]*))?\]\]', '[[' + title + ']]', data, 1)
  579. data = re.sub('\[\[(?P<in>\/[^\]|]*)(?P<out>\|(?:[^\]]*))?\]\]', '[[' + title + '\g<in>\g<out>]]', data)
  580. while(1):
  581. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  582. if(m):
  583. result = m.groups()
  584. rep = result[0]
  585. rep = re.sub("\\\#", "<sharp>", rep)
  586. a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
  587. results = a.groups()
  588. aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
  589. if(results[1]):
  590. g = re.sub("<sharp>", "#", results[1])
  591. else:
  592. g = re.sub("<sharp>", "#", results[0])
  593. results = aa.groups()
  594. if(not results[1]):
  595. sharp = ''
  596. else:
  597. sharp = results[1]
  598. b = re.search("^http(?:s)?:\/\/", results[0])
  599. if(b):
  600. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" rel="nofollow" target="_blank" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  601. else:
  602. if(results[0] == title):
  603. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  604. else:
  605. nosharp = re.sub("<sharp>", "#", results[0])
  606. curs.execute("select title from data where title = ?", [nosharp])
  607. y = curs.fetchall()
  608. if(y):
  609. clas = ''
  610. else:
  611. clas = 'not_thing'
  612. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + re.sub('(?:<a ([^>]*)>|<\/a>)', '', g) + '</a>', data, 1)
  613. backlink_plus(title, results[0], '', num)
  614. else:
  615. break
  616. while(1):
  617. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  618. if(m):
  619. result = m.groups()
  620. end = str(result[0])
  621. while(1):
  622. isspace = re.search("( +)\*\s([^\n]*)", end)
  623. if(isspace):
  624. spacebar = isspace.groups()
  625. up = len(spacebar[0]) * 20
  626. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  627. else:
  628. break
  629. end = re.sub("\n", '', end)
  630. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul style="margin-top: 10px;" id="list">' + end + '</ul>', data, 1)
  631. else:
  632. break
  633. now_time = get_time()
  634. data = re.sub('\[date\]', now_time, data)
  635. time_data = re.search('^([0-9]{4}-[0-9]{2}-[0-9]{2})', now_time)
  636. time = time_data.groups()
  637. age_data = re.findall('\[age\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  638. for age in age_data:
  639. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  640. will = datetime.datetime.strptime(age, '%Y-%m-%d')
  641. e_data = old - will
  642. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(int(int(e_data.days) / 365)), data, 1)
  643. dday_data = re.findall('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
  644. for dday in dday_data:
  645. old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
  646. will = datetime.datetime.strptime(dday, '%Y-%m-%d')
  647. e_data = old - will
  648. if(re.search('^-', str(e_data.days))):
  649. e_day = str(e_data.days)
  650. else:
  651. e_day = '+' + str(e_data.days)
  652. data = re.sub('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', e_day, data, 1)
  653. data = re.sub("-{4,11}", "<hr>", data)
  654. while(1):
  655. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  656. if(b):
  657. result = b.groups()
  658. up = re.sub(' ', '<span id="in"></span>', result[1])
  659. if(re.search('<\/h[0-9]>', result[0])):
  660. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  661. else:
  662. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  663. else:
  664. break
  665. a = 1
  666. tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
  667. namu = []
  668. while(1):
  669. b = re.search("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", data)
  670. if(b):
  671. results = b.groups()
  672. if(not results[1] and results[0]):
  673. i = 0
  674. while(1):
  675. try:
  676. if(namu[i] == results[0]):
  677. none_this = 0
  678. break
  679. else:
  680. i += 2
  681. except:
  682. none_this = 1
  683. break
  684. if(none_this == 0):
  685. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  686. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  687. </sup> \
  688. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  689. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + namu[i + 1] + " \
  690. </div>", data, 1)
  691. else:
  692. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  693. <a href='javascript:void(0);' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  694. </sup>", data, 1)
  695. else:
  696. if(results[0]):
  697. namu += [results[0]]
  698. namu += [results[1]]
  699. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + results[0] + "]</a> " + results[1] + "</span><br>"
  700. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", "<sup> \
  701. <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");' id='rfn-" + str(a) + "'>[" + results[0] + "]</a> \
  702. </sup> \
  703. <div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'> \
  704. <a onclick='folding(" + str(fol_num) + ");' href='#fn-" + str(a) + "'>[" + results[0] + "]</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>[X]</a> " + results[1] + " \
  705. </div>", data, 1)
  706. else:
  707. tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>[" + str(a) + "]</a> " + results[1] + "</span><br>"
  708. data = re.sub("\[\*([^\s]*)(?:\s(((?!\[|\]).)*))?\]", '<sup> \
  709. <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');" id="rfn-' + str(a) + '">[' + str(a) + ']</a> \
  710. </sup> \
  711. <div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"> \
  712. <a onclick="folding(' + str(fol_num) + ');" href="#fn-' + str(a) + '">[' + str(a) + ']</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">[X]</a> ' + results[1] + ' \
  713. </div>', data, 1)
  714. a += 1
  715. fol_num += 2
  716. else:
  717. tou += '</div>'
  718. if(tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>"):
  719. tou = ""
  720. break
  721. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  722. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  723. data = re.sub("\[각주\]", "<br>" + tou, data)
  724. data += tou
  725. if(category):
  726. data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
  727. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  728. while(1):
  729. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  730. if(y):
  731. a = y.groups()
  732. mid_data = re.sub("\|\|", "#table#", a[0])
  733. mid_data = re.sub("\r\n", "<br>", mid_data)
  734. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  735. else:
  736. break
  737. data = re.sub("#table#", "||", data)
  738. data = re.sub("<tablenobr>", "\r\n", data)
  739. while(1):
  740. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  741. if(m):
  742. results = m.groups()
  743. table = results[0]
  744. while(1):
  745. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  746. if(a):
  747. row = ''
  748. cel = ''
  749. celstyle = ''
  750. rowstyle = ''
  751. alltable = ''
  752. table_d = ''
  753. result = a.groups()
  754. if(result[1]):
  755. table_d = table_p(result[1], result[0])
  756. alltable = table_d[0]
  757. rowstyle = table_d[1]
  758. celstyle = table_d[2]
  759. row = table_d[3]
  760. cel = table_d[4]
  761. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  762. <tbody> \
  763. <tr " + rowstyle + "> \
  764. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  765. else:
  766. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  767. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  768. <tbody> \
  769. <tr> \
  770. <td " + cel + ">", table, 1)
  771. else:
  772. break
  773. table = re.sub("\|\|$", "</td> \
  774. </tr> \
  775. </tbody> \
  776. </table>", table)
  777. while(1):
  778. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  779. if(b):
  780. row = ''
  781. cel = ''
  782. celstyle = ''
  783. rowstyle = ''
  784. table_d = ''
  785. result = b.groups()
  786. if(result[1]):
  787. table_d = table_p(result[1], result[0])
  788. rowstyle = table_d[1]
  789. celstyle = table_d[2]
  790. row = table_d[3]
  791. cel = table_d[4]
  792. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  793. </tr> \
  794. <tr " + rowstyle + "> \
  795. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  796. else:
  797. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  798. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  799. </tr> \
  800. <tr> \
  801. <td " + cel + ">", table, 1)
  802. else:
  803. break
  804. while(1):
  805. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  806. if(c):
  807. row = ''
  808. cel = ''
  809. celstyle = ''
  810. table_d = ''
  811. result = c.groups()
  812. if(result[1]):
  813. table_d = table_p(result[1], result[0])
  814. celstyle = table_d[2]
  815. row = table_d[3]
  816. cel = table_d[4]
  817. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  818. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  819. else:
  820. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  821. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  822. <td " + cel + ">", table, 1)
  823. else:
  824. break
  825. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  826. else:
  827. break
  828. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  829. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  830. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  831. data = re.sub("<space>", " ", data)
  832. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  833. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  834. data = re.sub('\n', '<br>', data)
  835. data = re.sub('<isbr>', '\r\n', data)
  836. data = re.sub('^(?:<br>|\r|\n| )+', '', data)
  837. data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)
  838. conn.commit()
  839. return(data)