mark.py 48 KB

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