2
0

mark.py 51 KB

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