mark.py 48 KB

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