2
0

mark.py 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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, rowstyle, celstyle, 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=['\"]([^'\"]*)['\"]\r\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. table_d = ''
  818. result = a.groups()
  819. if(result[1]):
  820. table_d = table_p(result[1], result[0])
  821. alltable = table_d[0]
  822. rowstyle = table_d[1]
  823. celstyle = table_d[2]
  824. row = table_d[3]
  825. cel = table_d[4]
  826. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "> \
  827. <tbody> \
  828. <tr " + rowstyle + "> \
  829. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  830. else:
  831. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  832. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table> \
  833. <tbody> \
  834. <tr> \
  835. <td " + cel + ">", table, 1)
  836. else:
  837. break
  838. table = re.sub("\|\|$", "</td> \
  839. </tr> \
  840. </tbody> \
  841. </table>", table)
  842. while(1):
  843. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  844. if(b):
  845. row = ''
  846. cel = ''
  847. celstyle = ''
  848. rowstyle = ''
  849. table_d = ''
  850. result = b.groups()
  851. if(result[1]):
  852. table_d = table_p(result[1], result[0])
  853. rowstyle = table_d[1]
  854. celstyle = table_d[2]
  855. row = table_d[3]
  856. cel = table_d[4]
  857. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  858. </tr> \
  859. <tr " + rowstyle + "> \
  860. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  861. else:
  862. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  863. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  864. </tr> \
  865. <tr> \
  866. <td " + cel + ">", table, 1)
  867. else:
  868. break
  869. while(1):
  870. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  871. if(c):
  872. row = ''
  873. cel = ''
  874. celstyle = ''
  875. table_d = ''
  876. result = c.groups()
  877. if(result[1]):
  878. table_d = table_p(result[1], result[0])
  879. celstyle = table_d[2]
  880. row = table_d[3]
  881. cel = table_d[4]
  882. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  883. <td " + cel + " " + row + " " + celstyle + ">", table, 1)
  884. else:
  885. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  886. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td> \
  887. <td " + cel + ">", table, 1)
  888. else:
  889. break
  890. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  891. else:
  892. break
  893. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  894. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  895. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  896. data = re.sub("<space>", " ", data)
  897. data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
  898. data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
  899. data = re.sub('\n', '<br>', data)
  900. data = re.sub('<isbr>', '\r\n', data)
  901. data = re.sub('^<br>', '', data)
  902. data += "<script> \
  903. function folding(num) { \
  904. var fol = document.getElementById('folding_' + num); \
  905. if(fol.style.display == 'inline-block' || fol.style.display == 'block') { \
  906. fol.style.display = 'none'; \
  907. } else { \
  908. if(num % 3 == 0) { \
  909. fol.style.display = 'block'; \
  910. } else { \
  911. fol.style.display = 'inline-block'; \
  912. } \
  913. } \
  914. } \
  915. </script>"
  916. return(data)