mark.py 48 KB

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