mark.py 51 KB

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