mark.py 45 KB

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