2
0

mark.py 45 KB

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