mark.py 53 KB

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