mark.py 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  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 href='javascript:void(0);' id=\"rfn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + results[0] + "]</a></sup><span class='foot' id='footnote_" + str(a) + "' style='display:none;'><a class=\"footnotes\" href=\"#fn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + results[0] + "]</a> <a href='javascript:void(0);' onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[X]</a> " + namu[i + 1] + "</span>", 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. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  595. data = re.sub("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", "<sup><a href='javascript:void(0);' id=\"rfn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + results[0] + "]</a></sup><span class='foot' id='footnote_" + str(a) + "' style='display:none;'><a class=\"footnotes\" href=\"#fn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + results[0] + "]</a> <a href='javascript:void(0);' onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[X]</a> " + results[1] + "</span>", data, 1)
  596. else:
  597. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  598. data = re.sub("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", "<sup><a href='javascript:void(0);' id=\"rfn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + str(a) + "]</a></sup><span class='foot' id='footnote_" + str(a) + "' style='display:none;'><a class=\"footnotes\" href=\"#fn-" + str(a) + "\" onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[" + str(a) + "]</a> <a href='javascript:void(0);' onclick=\"var f=document.getElementById('footnote_" + str(a) + "');var s=f.style.display=='inline';f.style.display=s?'none':'inline';this.className=s?'':'opened';\">[X]</a> " + results[1] + "</span>", data, 1)
  599. a += 1
  600. else:
  601. tou += '</div>'
  602. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  603. tou = ""
  604. break
  605. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  606. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  607. data = re.sub("\[각주\]", "<br>" + tou, data)
  608. data = data + tou
  609. if(category):
  610. data = data + '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
  611. data = re.sub("(?:\|\|\r\n)", "#table#<nobr>", data)
  612. while(True):
  613. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  614. if(y):
  615. a = y.groups()
  616. mid_data = re.sub("\|\|", "#table#", a[0])
  617. mid_data = re.sub("\r\n", "<br>", mid_data)
  618. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  619. else:
  620. break
  621. data = re.sub("#table#", "||", data)
  622. data = re.sub("<nobr>", "\r\n", data)
  623. while(True):
  624. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  625. if(m):
  626. results = m.groups()
  627. table = results[0]
  628. while(True):
  629. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  630. if(a):
  631. row = ''
  632. cel = ''
  633. celstyle = ''
  634. rowstyle = ''
  635. alltable = ''
  636. result = a.groups()
  637. if(result[1]):
  638. alltable = 'style="'
  639. celstyle = 'style="'
  640. rowstyle = 'style="'
  641. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  642. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  643. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  644. if(q):
  645. resultss = q.groups()
  646. alltable = alltable + 'width:' + resultss[0] + ';'
  647. if(w):
  648. resultss = w.groups()
  649. alltable = alltable + 'height:' + resultss[0] + ';'
  650. if(e):
  651. resultss = e.groups()
  652. if(resultss[0] == 'right'):
  653. alltable = alltable + 'margin-left:auto;'
  654. elif(resultss[0] == 'center'):
  655. alltable = alltable + 'margin:auto;'
  656. else:
  657. alltable = alltable + 'margin-right:auto;'
  658. ee = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", result[1])
  659. if(ee):
  660. resultss = ee.groups()
  661. if(resultss[0] == 'right'):
  662. alltable = alltable + 'text-align:right;'
  663. elif(resultss[0] == 'center'):
  664. alltable = alltable + 'text-align:center;'
  665. else:
  666. alltable = alltable + 'text-align:left;'
  667. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  668. if(r):
  669. resultss = r.groups()
  670. cel = 'colspan="' + resultss[0] + '"'
  671. else:
  672. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  673. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  674. if(t):
  675. resultss = t.groups()
  676. row = 'rowspan="' + resultss[0] + '"'
  677. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  678. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  679. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  680. if(ba):
  681. resultss = ba.groups()
  682. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  683. elif(bb):
  684. resultss = bb.groups()
  685. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  686. elif(bc):
  687. resultss = bc.groups()
  688. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  689. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  690. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  691. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  692. if(z):
  693. resultss = z.groups()
  694. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  695. elif(x):
  696. resultss = x.groups()
  697. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  698. elif(c):
  699. resultss = c.groups()
  700. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  701. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  702. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  703. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  704. if(aq):
  705. resultss = aq.groups()
  706. alltable = alltable + 'background:' + resultss[0] + ';'
  707. elif(aw):
  708. resultss = aw.groups()
  709. alltable = alltable + 'background:' + resultss[0] + ';'
  710. elif(ae):
  711. resultss = ae.groups()
  712. alltable = alltable + 'background:' + resultss[0] + ';'
  713. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  714. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  715. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  716. if(j):
  717. resultss = j.groups()
  718. celstyle = celstyle + 'background:' + resultss[0] + ';'
  719. elif(k):
  720. resultss = k.groups()
  721. celstyle = celstyle + 'background:' + resultss[0] + ';'
  722. elif(l):
  723. resultss = l.groups()
  724. celstyle = celstyle + 'background:' + resultss[0] + ';'
  725. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  726. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  727. ac = re.search("&lt;(\w+)&gt;", result[1])
  728. if(aa):
  729. resultss = aa.groups()
  730. celstyle = celstyle + 'background:' + resultss[0] + ';'
  731. elif(ab):
  732. resultss = ab.groups()
  733. celstyle = celstyle + 'background:' + resultss[0] + ';'
  734. elif(ac):
  735. resultss = ac.groups()
  736. celstyle = celstyle + 'background:' + resultss[0] + ';'
  737. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  738. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  739. if(qa):
  740. resultss = qa.groups()
  741. celstyle = celstyle + 'width:' + resultss[0] + ';'
  742. if(qb):
  743. resultss = qb.groups()
  744. celstyle = celstyle + 'height:' + resultss[0] + ';'
  745. i = re.search("&lt;\)&gt;", result[1])
  746. o = re.search("&lt;:&gt;", result[1])
  747. p = re.search("&lt;\(&gt;", result[1])
  748. if(i):
  749. celstyle = celstyle + 'text-align:right;'
  750. elif(o):
  751. celstyle = celstyle + 'text-align:center;'
  752. elif(p):
  753. celstyle = celstyle + 'text-align:left;'
  754. alltable = alltable + '"'
  755. celstyle = celstyle + '"'
  756. rowstyle = rowstyle + '"'
  757. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  758. else:
  759. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  760. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  761. else:
  762. break
  763. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  764. while(True):
  765. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  766. if(b):
  767. row = ''
  768. cel = ''
  769. celstyle = ''
  770. rowstyle = ''
  771. result = b.groups()
  772. if(result[1]):
  773. celstyle = 'style="'
  774. rowstyle = 'style="'
  775. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  776. if(r):
  777. resultss = r.groups()
  778. cel = 'colspan="' + resultss[0] + '"'
  779. else:
  780. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  781. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  782. if(t):
  783. resultss = t.groups()
  784. row = 'rowspan="' + resultss[0] + '"'
  785. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  786. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  787. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  788. if(ba):
  789. resultss = ba.groups()
  790. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  791. elif(bb):
  792. resultss = bb.groups()
  793. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  794. elif(bc):
  795. resultss = bc.groups()
  796. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  797. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  798. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  799. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  800. if(j):
  801. resultss = j.groups()
  802. celstyle = celstyle + 'background:' + resultss[0] + ';'
  803. elif(k):
  804. resultss = k.groups()
  805. celstyle = celstyle + 'background:' + resultss[0] + ';'
  806. elif(l):
  807. resultss = l.groups()
  808. celstyle = celstyle + 'background:' + resultss[0] + ';'
  809. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  810. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  811. ac = re.search("&lt;(\w+)&gt;", result[1])
  812. if(aa):
  813. resultss = aa.groups()
  814. celstyle = celstyle + 'background:' + resultss[0] + ';'
  815. elif(ab):
  816. resultss = ab.groups()
  817. celstyle = celstyle + 'background:' + resultss[0] + ';'
  818. elif(ac):
  819. resultss = ac.groups()
  820. celstyle = celstyle + 'background:' + resultss[0] + ';'
  821. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  822. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  823. if(qa):
  824. resultss = qa.groups()
  825. celstyle = celstyle + 'width:' + resultss[0] + ';'
  826. if(qb):
  827. resultss = qb.groups()
  828. celstyle = celstyle + 'height:' + resultss[0] + ';'
  829. i = re.search("&lt;\)&gt;", result[1])
  830. o = re.search("&lt;:&gt;", result[1])
  831. p = re.search("&lt;\(&gt;", result[1])
  832. if(i):
  833. celstyle = celstyle + 'text-align:right;'
  834. elif(o):
  835. celstyle = celstyle + 'text-align:center;'
  836. elif(p):
  837. celstyle = celstyle + 'text-align:left;'
  838. celstyle = celstyle + '"'
  839. rowstyle = rowstyle + '"'
  840. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  841. else:
  842. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  843. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  844. else:
  845. break
  846. while(True):
  847. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  848. if(c):
  849. row = ''
  850. cel = ''
  851. celstyle = ''
  852. result = c.groups()
  853. if(result[1]):
  854. celstyle = 'style="'
  855. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  856. if(r):
  857. resultss = r.groups()
  858. cel = 'colspan="' + resultss[0] + '"';
  859. else:
  860. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  861. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  862. if(t):
  863. resultss = t.groups()
  864. row = 'rowspan="' + resultss[0] + '"';
  865. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  866. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  867. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  868. if(j):
  869. resultss = j.groups()
  870. celstyle = celstyle + 'background:' + resultss[0] + ';'
  871. elif(k):
  872. resultss = k.groups()
  873. celstyle = celstyle + 'background:' + resultss[0] + ';'
  874. elif(l):
  875. resultss = l.groups()
  876. celstyle = celstyle + 'background:' + resultss[0] + ';'
  877. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  878. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  879. ac = re.search("&lt;(\w+)&gt;", result[1])
  880. if(aa):
  881. resultss = aa.groups()
  882. celstyle = celstyle + 'background:' + resultss[0] + ';'
  883. elif(ab):
  884. resultss = ab.groups()
  885. celstyle = celstyle + 'background:' + resultss[0] + ';'
  886. elif(ac):
  887. resultss = ac.groups()
  888. celstyle = celstyle + 'background:' + resultss[0] + ';'
  889. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  890. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  891. if(qa):
  892. resultss = qa.groups()
  893. celstyle = celstyle + 'width:' + resultss[0] + ';'
  894. if(qb):
  895. resultss = qb.groups()
  896. celstyle = celstyle + 'height:' + resultss[0] + ';'
  897. i = re.search("&lt;\)&gt;", result[1])
  898. o = re.search("&lt;:&gt;", result[1])
  899. p = re.search("&lt;\(&gt;", result[1])
  900. if(i):
  901. celstyle = celstyle + 'text-align:right;'
  902. elif(o):
  903. celstyle = celstyle + 'text-align:center;'
  904. elif(p):
  905. celstyle = celstyle + 'text-align:left;'
  906. celstyle = celstyle + '"'
  907. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  908. else:
  909. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  910. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  911. else:
  912. break
  913. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  914. else:
  915. break
  916. data = re.sub("(\n#nobr#|#nobr#\n|#nobr#)", "", data)
  917. data = re.sub('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
  918. data = re.sub('\n', '<br>', data)
  919. data = re.sub('^<br>', '', data)
  920. return data