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