mark.py 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]")
  182. while(True):
  183. m = include.search(data)
  184. if(m):
  185. results = m.groups()
  186. if(results[0] == title):
  187. data = include.sub("<b>" + results[0] + "</b>", data, 1)
  188. else:
  189. db_ex("select * from data where title = '" + db_pas(results[0]) + "'")
  190. in_con = db_get()
  191. backlink_plus(title, results[0], 'include')
  192. if(in_con):
  193. in_data = in_con[0]['data']
  194. in_data = include.sub("", in_data)
  195. in_data = html_pas(in_data, 1)
  196. in_data = mid_pas(in_data, b, True)[0]
  197. if(results[1]):
  198. a = results[1]
  199. while(True):
  200. g = re.search("([^= ,]*)\=([^,]*)", a)
  201. if(g):
  202. result = g.groups()
  203. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  204. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  205. else:
  206. break
  207. data = include.sub('\n<nobr><div>' + in_data + '</div><nobr>\n', data, 1)
  208. else:
  209. data = include.sub("<a class=\"not_thing\" href=\"" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  210. else:
  211. break
  212. while(True):
  213. m = re.search('^#(?:redirect|넘겨주기) ([^\n]*)$', data)
  214. if(m):
  215. results = m.groups()
  216. aa = re.search("^([^\n]*)(#(?:[^\n]*))$", results[0])
  217. if(aa):
  218. results = aa.groups()
  219. data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(results[0]) + '/from/' + url_pas(title) + results[1] + '" />', data, 1)
  220. else:
  221. data = re.sub('^#(?:redirect|넘겨주기) ([^\n]*)$', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(results[0]) + '/from/' + url_pas(title) + '" />', data, 1)
  222. backlink_plus(title, results[0], 'redirect')
  223. else:
  224. break
  225. data = '\n' + data + '\n'
  226. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  227. while(True):
  228. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  229. if(m):
  230. result = m.groups()
  231. blockquote = result[0]
  232. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  233. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  234. else:
  235. break
  236. if(not re.search('\[목차\]', data)):
  237. if(not re.search('\[목차\(없음\)\]', data)):
  238. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  239. else:
  240. data = re.sub("\[목차\(없음\)\]", "", data)
  241. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  242. i = [0, 0, 0, 0, 0, 0, 0]
  243. last = 0
  244. span = ''
  245. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  246. while(True):
  247. i[0] += 1
  248. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
  249. if(m):
  250. result = m.groups()
  251. wiki = len(result[0])
  252. if(last < wiki):
  253. last = wiki
  254. else:
  255. last = wiki
  256. if(wiki == 1):
  257. i[2] = 0
  258. i[3] = 0
  259. i[4] = 0
  260. i[5] = 0
  261. i[6] = 0
  262. elif(wiki == 2):
  263. i[3] = 0
  264. i[4] = 0
  265. i[5] = 0
  266. i[6] = 0
  267. elif(wiki == 3):
  268. i[4] = 0
  269. i[5] = 0
  270. i[6] = 0
  271. elif(wiki == 4):
  272. i[5] = 0
  273. i[6] = 0
  274. elif(wiki == 5):
  275. i[6] = 0
  276. if(wiki == 1):
  277. i[1] += 1
  278. elif(wiki == 2):
  279. i[2] += 1
  280. elif(wiki == 3):
  281. i[3] += 1
  282. elif(wiki == 4):
  283. i[4] += 1
  284. elif(wiki == 5):
  285. i[5] += 1
  286. else:
  287. i[6] += 1
  288. toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
  289. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  290. toc = re.sub("0\.", '', toc)
  291. toc = re.sub("#\.", '.', toc)
  292. toc = re.sub("\.$", '', toc)
  293. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  294. if(test):
  295. g = test.groups()
  296. if(g[4]):
  297. span = '<span id="out"></span>' * 4
  298. elif(g[3]):
  299. span = '<span id="out"></span>' * 3
  300. elif(g[2]):
  301. span = '<span id="out"></span>' * 2
  302. elif(g[1]):
  303. span = '<span id="out"></span>'
  304. else:
  305. span = ''
  306. rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  307. c = re.sub(" $", "", result[1])
  308. d = c
  309. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  310. 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);
  311. else:
  312. rtoc += '</div>'
  313. break
  314. data = re.sub("\[목차\]", rtoc, data)
  315. category = ''
  316. while(True):
  317. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  318. if(m):
  319. g = m.groups()
  320. if(not title == g[0]):
  321. cat_plus(title, g[0])
  322. if(category == ''):
  323. db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
  324. exists = db_get()
  325. if(exists):
  326. red = ""
  327. else:
  328. red = 'class="not_thing"'
  329. category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  330. else:
  331. db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
  332. exists = db_get()
  333. if(exists):
  334. red = ""
  335. else:
  336. red = 'class="not_thing"'
  337. category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  338. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  339. else:
  340. break
  341. data = re.sub("'''(?P<in>.+?)'''(?!')", '<b>\g<in></b>', data)
  342. data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
  343. data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
  344. data = re.sub('--(?P<in>.+?)--(?!-)', '<s>\g<in></s>', data)
  345. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  346. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  347. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  348. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  349. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
  350. data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby>\g<in><rp>(</rp><rt>\g<out></rt><rp>)</rp></ruby>', data)
  351. data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data)
  352. while(True):
  353. m = re.search("\[\[파일:((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  354. if(m):
  355. c = m.groups()
  356. if(c):
  357. if(not re.search("^파일:([^\n]*)", title)):
  358. backlink_plus(title, '파일:' + c[0], 'file')
  359. comp = re.compile("^(.+)(\.(?:jpg|gif|png|jpeg))$", re.I)
  360. if(c[1]):
  361. n = re.search("width=([^ \n&]*)", c[1])
  362. e = re.search("height=([^ \n&]*)", c[1])
  363. if(n):
  364. a = n.groups()
  365. width = a[0]
  366. else:
  367. width = ''
  368. if(e):
  369. b = e.groups()
  370. height = b[0]
  371. else:
  372. height = ''
  373. try:
  374. extension = comp.search(c[0]).groups()
  375. comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
  376. img = comp.sub("#\g<in>#", extension[1])
  377. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + extension[0] + img + '"><img src="/image/' + sha224(extension[0]) + img + '" width="' + width + '" height="' + height + '"></a>', data, 1)
  378. except:
  379. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
  380. else:
  381. try:
  382. extension = comp.search(c[0]).groups()
  383. comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
  384. img = comp.sub("#\g<in>#", extension[1])
  385. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<a href='/w/파일:" + extension[0] + img + "'><img src='/image/" + sha224(extension[0]) + img + "'></a>", data, 1)
  386. except:
  387. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
  388. else:
  389. break
  390. else:
  391. break
  392. data = re.sub("\[br\]",'<br>', data)
  393. while(True):
  394. com = re.compile("\[youtube\(([^, )]*)(,[^)]*)?\)\]")
  395. m = com.search(data)
  396. if(m):
  397. src = ''
  398. width = '560'
  399. height = '315'
  400. time = '0'
  401. result = m.groups()
  402. if(result[0]):
  403. yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9]*))$', result[0])
  404. if(yudt.groups()[0]):
  405. src = yudt.groups()[0]
  406. elif(yudt.groups()[1]):
  407. src = yudt.groups()[1]
  408. elif(yudt.groups()[2]):
  409. src = yudt.groups()[2]
  410. if(result[1]):
  411. mdata = re.search('width=([0-9]*)', result[1])
  412. if(mdata):
  413. width = mdata.groups()[0]
  414. mdata = re.search('height=([0-9]*)', result[1])
  415. if(mdata):
  416. height = mdata.groups()[0]
  417. mdata = re.search('time=([0-9]*)', result[1])
  418. if(mdata):
  419. time = mdata.groups()[0]
  420. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  421. else:
  422. break
  423. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  424. while(True):
  425. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  426. if(m):
  427. result = m.groups()
  428. rep = result[0]
  429. rep = re.sub("\\\#", "<sharp>", rep)
  430. a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
  431. results = a.groups()
  432. aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
  433. if(results[1]):
  434. g = re.sub("<sharp>", "#", results[1])
  435. else:
  436. g = re.sub("<sharp>", "#", results[0])
  437. results = aa.groups()
  438. if(not results[1]):
  439. sharp = ''
  440. else:
  441. sharp = results[1]
  442. b = re.search("^http(?:s)?:\/\/", results[0])
  443. if(b):
  444. comp = re.compile("(?:\.(?:jpg|png|gif|jpeg))", re.I)
  445. c = comp.search(results[0])
  446. if(c):
  447. img = results[0]
  448. comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
  449. img = comp.sub("#\g<in>#", img)
  450. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + sharp + '">' + g + '</a>', data, 1)
  451. else:
  452. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
  453. else:
  454. if(results[0] == title):
  455. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  456. else:
  457. db_ex("select title from data where title = '" + db_pas(results[0]) + "'")
  458. y = db_get()
  459. if(y):
  460. clas = ''
  461. else:
  462. clas = 'not_thing'
  463. nosharp = re.sub("<sharp>", "#", results[0])
  464. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + g + '</a>', data, 1)
  465. backlink_plus(title, results[0], '')
  466. else:
  467. break
  468. while(True):
  469. com = re.compile("(http(?:s)?:\/\/(?:(?:(?:(?!\.(?:jpg|png|gif|jpeg)|#(?:jpg|png|gif|jpeg)#|<\/(?:[^>]*)>).)*)(?:\.(?:jpg|png|gif|jpeg))))(\?[^ \r\n]*)?", re.I)
  470. m = com.search(data)
  471. if(m):
  472. width = ''
  473. height = ''
  474. align = ''
  475. result = m.groups()
  476. if(result[1]):
  477. mdata = re.search('width=([0-9]*)', result[1])
  478. if(mdata):
  479. width = mdata.groups()[0]
  480. mdata = re.search('height=([0-9]*)', result[1])
  481. if(mdata):
  482. height = mdata.groups()[0]
  483. mdata = re.search('align=([^&]*)', result[1])
  484. if(mdata):
  485. if(mdata.groups()[0] == 'right'):
  486. align = 'right'
  487. elif(mdata.groups()[0] == 'center'):
  488. align = 'center'
  489. c = result[0]
  490. comp = re.compile("\.(?P<in>jpg|gif|png|jpeg)", re.I)
  491. c = comp.sub("#\g<in>#", c)
  492. data = com.sub("<img align='" + align + "' width='" + width + "' height='" + height + "' src='" + c + "'></table>", data, 1)
  493. else:
  494. break
  495. while(True):
  496. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  497. if(m):
  498. result = m.groups()
  499. end = str(result[0])
  500. while(True):
  501. isspace = re.search("( +)\*\s([^\n]*)", end)
  502. if(isspace):
  503. spacebar = isspace.groups()
  504. up = len(spacebar[0]) * 20
  505. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  506. else:
  507. break
  508. end = re.sub("\n", '', end)
  509. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
  510. else:
  511. break
  512. now_time = get_time()
  513. data = re.sub('\[date\]', now_time, data)
  514. time_data = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
  515. time = time_data.groups()
  516. age_data = re.findall('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', data)
  517. for age in age_data:
  518. year = int(time[0]) - int(age[0])
  519. if(age[1] > time[1]):
  520. year -= 1
  521. elif(age[1] == time[1]):
  522. if(age[2] > time[2]):
  523. year -= 1
  524. data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
  525. comp = re.compile("#(?P<in>jpg|gif|png|jpeg)#", re.I)
  526. data = comp.sub(".\g<in>", data)
  527. data = re.sub("-{4,11}", "<hr>", data)
  528. while(True):
  529. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  530. if(b):
  531. result = b.groups()
  532. up = re.sub(' ', '<span id="in"></span>', result[1])
  533. if(re.search('<\/h[0-9]>', result[0])):
  534. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  535. else:
  536. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  537. else:
  538. break
  539. a = 1
  540. tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
  541. namu = []
  542. while(True):
  543. b = re.search("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", data)
  544. if(b):
  545. results = b.groups()
  546. if(not results[1] and results[0]):
  547. i = 0
  548. while(True):
  549. try:
  550. if(namu[i] == results[0]):
  551. none_this = False
  552. break
  553. else:
  554. i += 2
  555. except:
  556. none_this = True
  557. break
  558. if(none_this == False):
  559. 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)
  560. else:
  561. data = re.sub("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", "<sup><a class=\"footnotes\" id=\"rfn-" + str(a) + "\" href=\"#fn-" + str(a) + "\">[" + results[0] + "]</a></sup>", data, 1)
  562. elif(results[0]):
  563. namu += [results[0]]
  564. namu += [results[1]]
  565. c = results[1]
  566. c = re.sub("<(?:[^>]*)>", '', c)
  567. tou += "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  568. 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)
  569. a += 1
  570. else:
  571. c = results[1]
  572. c = re.sub("<(?:[^>]*)>", '', c)
  573. tou += "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  574. 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)
  575. else:
  576. tou += '</div>'
  577. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  578. tou = ""
  579. break
  580. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  581. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  582. data = re.sub("\[각주\]", "<br>" + tou, data)
  583. data += tou
  584. if(category):
  585. data += '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
  586. data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
  587. while(True):
  588. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  589. if(y):
  590. a = y.groups()
  591. mid_data = re.sub("\|\|", "#table#", a[0])
  592. mid_data = re.sub("\r\n", "<br>", mid_data)
  593. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  594. else:
  595. break
  596. data = re.sub("#table#", "||", data)
  597. data = re.sub("<tablenobr>", "\r\n", data)
  598. while(True):
  599. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  600. if(m):
  601. results = m.groups()
  602. table = results[0]
  603. while(True):
  604. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  605. if(a):
  606. row = ''
  607. cel = ''
  608. celstyle = ''
  609. rowstyle = ''
  610. alltable = ''
  611. result = a.groups()
  612. if(result[1]):
  613. alltable = 'style="'
  614. celstyle = 'style="'
  615. rowstyle = 'style="'
  616. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  617. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  618. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  619. if(q):
  620. resultss = q.groups()
  621. alltable += 'width:' + resultss[0] + ';'
  622. if(w):
  623. resultss = w.groups()
  624. alltable += 'height:' + resultss[0] + ';'
  625. if(e):
  626. resultss = e.groups()
  627. if(resultss[0] == 'right'):
  628. alltable += 'margin-left:auto;'
  629. elif(resultss[0] == 'center'):
  630. alltable += 'margin:auto;'
  631. else:
  632. alltable += 'margin-right:auto;'
  633. ee = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", result[1])
  634. if(ee):
  635. resultss = ee.groups()
  636. if(resultss[0] == 'right'):
  637. alltable += 'text-align:right;'
  638. elif(resultss[0] == 'center'):
  639. alltable += 'text-align:center;'
  640. else:
  641. alltable += 'text-align:left;'
  642. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  643. if(r):
  644. resultss = r.groups()
  645. cel = 'colspan="' + resultss[0] + '"'
  646. else:
  647. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  648. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  649. if(t):
  650. resultss = t.groups()
  651. row = 'rowspan="' + resultss[0] + '"'
  652. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  653. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  654. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  655. if(ba):
  656. resultss = ba.groups()
  657. rowstyle += 'background:' + resultss[0] + ';'
  658. elif(bb):
  659. resultss = bb.groups()
  660. rowstyle += 'background:' + resultss[0] + ';'
  661. elif(bc):
  662. resultss = bc.groups()
  663. rowstyle += 'background:' + resultss[0] + ';'
  664. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  665. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  666. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  667. if(z):
  668. resultss = z.groups()
  669. alltable += 'border:' + resultss[0] + ' 2px solid;'
  670. elif(x):
  671. resultss = x.groups()
  672. alltable += 'border:' + resultss[0] + ' 2px solid;'
  673. elif(c):
  674. resultss = c.groups()
  675. alltable += 'border:' + resultss[0] + ' 2px solid;'
  676. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  677. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  678. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  679. if(aq):
  680. resultss = aq.groups()
  681. alltable += 'background:' + resultss[0] + ';'
  682. elif(aw):
  683. resultss = aw.groups()
  684. alltable += 'background:' + resultss[0] + ';'
  685. elif(ae):
  686. resultss = ae.groups()
  687. alltable += 'background:' + resultss[0] + ';'
  688. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  689. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  690. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  691. if(j):
  692. resultss = j.groups()
  693. celstyle += 'background:' + resultss[0] + ';'
  694. elif(k):
  695. resultss = k.groups()
  696. celstyle += 'background:' + resultss[0] + ';'
  697. elif(l):
  698. resultss = l.groups()
  699. celstyle += 'background:' + resultss[0] + ';'
  700. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  701. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  702. ac = re.search("&lt;(\w+)&gt;", result[1])
  703. if(aa):
  704. resultss = aa.groups()
  705. celstyle += 'background:' + resultss[0] + ';'
  706. elif(ab):
  707. resultss = ab.groups()
  708. celstyle += 'background:' + resultss[0] + ';'
  709. elif(ac):
  710. resultss = ac.groups()
  711. celstyle += 'background:' + resultss[0] + ';'
  712. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  713. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  714. if(qa):
  715. resultss = qa.groups()
  716. celstyle += 'width:' + resultss[0] + ';'
  717. if(qb):
  718. resultss = qb.groups()
  719. celstyle += 'height:' + resultss[0] + ';'
  720. i = re.search("&lt;\)&gt;", result[1])
  721. o = re.search("&lt;:&gt;", result[1])
  722. p = re.search("&lt;\(&gt;", result[1])
  723. if(i):
  724. celstyle += 'text-align:right;'
  725. elif(o):
  726. celstyle += 'text-align:center;'
  727. elif(p):
  728. celstyle += 'text-align:left;'
  729. alltable += '"'
  730. celstyle += '"'
  731. rowstyle += '"'
  732. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  733. else:
  734. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  735. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  736. else:
  737. break
  738. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  739. while(True):
  740. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  741. if(b):
  742. row = ''
  743. cel = ''
  744. celstyle = ''
  745. rowstyle = ''
  746. result = b.groups()
  747. if(result[1]):
  748. celstyle = 'style="'
  749. rowstyle = 'style="'
  750. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  751. if(r):
  752. resultss = r.groups()
  753. cel = 'colspan="' + resultss[0] + '"'
  754. else:
  755. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  756. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  757. if(t):
  758. resultss = t.groups()
  759. row = 'rowspan="' + resultss[0] + '"'
  760. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  761. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  762. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  763. if(ba):
  764. resultss = ba.groups()
  765. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  766. elif(bb):
  767. resultss = bb.groups()
  768. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  769. elif(bc):
  770. resultss = bc.groups()
  771. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  772. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  773. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  774. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  775. if(j):
  776. resultss = j.groups()
  777. celstyle = celstyle + 'background:' + resultss[0] + ';'
  778. elif(k):
  779. resultss = k.groups()
  780. celstyle = celstyle + 'background:' + resultss[0] + ';'
  781. elif(l):
  782. resultss = l.groups()
  783. celstyle = celstyle + 'background:' + resultss[0] + ';'
  784. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  785. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  786. ac = re.search("&lt;(\w+)&gt;", result[1])
  787. if(aa):
  788. resultss = aa.groups()
  789. celstyle = celstyle + 'background:' + resultss[0] + ';'
  790. elif(ab):
  791. resultss = ab.groups()
  792. celstyle = celstyle + 'background:' + resultss[0] + ';'
  793. elif(ac):
  794. resultss = ac.groups()
  795. celstyle = celstyle + 'background:' + resultss[0] + ';'
  796. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  797. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  798. if(qa):
  799. resultss = qa.groups()
  800. celstyle = celstyle + 'width:' + resultss[0] + ';'
  801. if(qb):
  802. resultss = qb.groups()
  803. celstyle = celstyle + 'height:' + resultss[0] + ';'
  804. i = re.search("&lt;\)&gt;", result[1])
  805. o = re.search("&lt;:&gt;", result[1])
  806. p = re.search("&lt;\(&gt;", result[1])
  807. if(i):
  808. celstyle = celstyle + 'text-align:right;'
  809. elif(o):
  810. celstyle = celstyle + 'text-align:center;'
  811. elif(p):
  812. celstyle = celstyle + 'text-align:left;'
  813. celstyle = celstyle + '"'
  814. rowstyle = rowstyle + '"'
  815. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  816. else:
  817. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  818. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  819. else:
  820. break
  821. while(True):
  822. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  823. if(c):
  824. row = ''
  825. cel = ''
  826. celstyle = ''
  827. result = c.groups()
  828. if(result[1]):
  829. celstyle = 'style="'
  830. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  831. if(r):
  832. resultss = r.groups()
  833. cel = 'colspan="' + resultss[0] + '"';
  834. else:
  835. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  836. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  837. if(t):
  838. resultss = t.groups()
  839. row = 'rowspan="' + resultss[0] + '"';
  840. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  841. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  842. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  843. if(j):
  844. resultss = j.groups()
  845. celstyle = celstyle + 'background:' + resultss[0] + ';'
  846. elif(k):
  847. resultss = k.groups()
  848. celstyle = celstyle + 'background:' + resultss[0] + ';'
  849. elif(l):
  850. resultss = l.groups()
  851. celstyle = celstyle + 'background:' + resultss[0] + ';'
  852. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  853. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  854. ac = re.search("&lt;(\w+)&gt;", result[1])
  855. if(aa):
  856. resultss = aa.groups()
  857. celstyle = celstyle + 'background:' + resultss[0] + ';'
  858. elif(ab):
  859. resultss = ab.groups()
  860. celstyle = celstyle + 'background:' + resultss[0] + ';'
  861. elif(ac):
  862. resultss = ac.groups()
  863. celstyle = celstyle + 'background:' + resultss[0] + ';'
  864. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  865. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  866. if(qa):
  867. resultss = qa.groups()
  868. celstyle = celstyle + 'width:' + resultss[0] + ';'
  869. if(qb):
  870. resultss = qb.groups()
  871. celstyle = celstyle + 'height:' + resultss[0] + ';'
  872. i = re.search("&lt;\)&gt;", result[1])
  873. o = re.search("&lt;:&gt;", result[1])
  874. p = re.search("&lt;\(&gt;", result[1])
  875. if(i):
  876. celstyle = celstyle + 'text-align:right;'
  877. elif(o):
  878. celstyle = celstyle + 'text-align:center;'
  879. elif(p):
  880. celstyle = celstyle + 'text-align:left;'
  881. celstyle = celstyle + '"'
  882. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  883. else:
  884. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  885. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  886. else:
  887. break
  888. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  889. else:
  890. break
  891. data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
  892. data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
  893. data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
  894. data = re.sub("<space>", " ", data)
  895. data = re.sub('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
  896. data = re.sub('\n', '<br>', data)
  897. data = re.sub('^<br>', '', data)
  898. return(data)