mark.py 48 KB

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