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