mark.py 48 KB

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