mark.py 50 KB

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