mark.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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, how):
  20. while(True):
  21. if(how == 1):
  22. y = re.search("<((a|div|span|embed|iframe)(?:[^>]*))>", data)
  23. else:
  24. y = re.search("<((a)(?:[^>]*))>", data)
  25. if(y):
  26. b = y.groups()
  27. if(re.search("<(\/" + b[1] + ")>", data)):
  28. xss_test = re.search('src=(?:"|\')(http(s)?:\/\/([^\/]*)\/(?:[^"\']*))(?:"|\')', b[0])
  29. if(xss_test):
  30. check = xss_test.groups()
  31. if(check[2] == "www.youtube.com" or check[2] == "serviceapi.nmv.naver.com" or check[2] == "tv.kakao.com" or check[2] == "tvple.com"):
  32. a = b[0]
  33. else:
  34. a = re.sub('src=(?:"|\')([^"\']*)(?:"|\')', '', b[0])
  35. else:
  36. a = b[0]
  37. a = re.sub('(?:"|\')', '#.#', a)
  38. if(check):
  39. if(not check[1] == None):
  40. data = re.sub("<((?:\/)?" + b[1] + "(?:[^>]*))>", "[" + a + "]", data, 1)
  41. data = re.sub("<\/" + b[1] + ">", "[/" + b[1] + "]", data, 1)
  42. else:
  43. data = re.sub("<((?:\/)?" + b[1] + "(?:[^>]*))>", "[[" + check[0] + "]]", data, 1)
  44. data = re.sub("<\/" + b[1] + ">", "", data, 1)
  45. else:
  46. data = re.sub("<((?:\/)?" + b[1] + "(?:[^>]*))>", "[" + a + "]", data, 1)
  47. data = re.sub("<\/" + b[1] + ">", "[/" + b[1] + "]", data, 1)
  48. else:
  49. data = re.sub("<((?:\/)?" + b[1] + "(?:[^>]*))>", '&lt;' + b[0] + '&gt;', data, 1)
  50. break
  51. else:
  52. break
  53. data = re.sub('<', '&lt;', data)
  54. data = re.sub('>', '&gt;', data)
  55. data = re.sub('"', '&quot;', data)
  56. data = re.sub("\[(?P<in>(?:\/)?(?:a|div|span|embed|iframe)(?:[^\]]*))\]", "<\g<in>>", data)
  57. data = re.sub('#.#', '"', data)
  58. return data
  59. def mid_pas(data, fol_num, include):
  60. while(True):
  61. com = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL)
  62. y = com.search(data)
  63. if(y):
  64. a = y.groups()
  65. big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
  66. big = big_a.search(a[0])
  67. small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
  68. small = small_a.search(a[0])
  69. color_a = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  70. color = color_a.search(a[0])
  71. color_b = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  72. color_2 = color_b.search(a[0])
  73. color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
  74. color_3 = color_c.search(a[0])
  75. back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
  76. back = back_a.search(a[0])
  77. back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
  78. back_2 = back_b.search(a[0])
  79. back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
  80. back_3 = back_c.search(a[0])
  81. include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
  82. include_out = include_out_a.search(a[0])
  83. div_a = re.compile("^#!wiki\sstyle=&quot;((?:(?!&quot;|\n).)*)&quot;\n?\s\n(.*)$", re.DOTALL)
  84. div = div_a.search(a[0])
  85. html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
  86. html = html_a.search(a[0])
  87. fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
  88. fol = fol_a.search(a[0])
  89. if(big):
  90. result = big.groups()
  91. data = com.sub('<span class="font-size-' + result[0] + '">' + result[1] + '</span>', data, 1)
  92. elif(small):
  93. result = small.groups()
  94. data = com.sub('<span class="font-size-small-' + result[0] + '">' + result[1] + '</span>', data, 1)
  95. elif(color):
  96. result = color.groups()
  97. data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  98. elif(color_2):
  99. result = color_2.groups()
  100. data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  101. elif(color_3):
  102. result = color_3.groups()
  103. data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
  104. elif(back):
  105. result = back.groups()
  106. data = com.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
  107. elif(back_2):
  108. result = back_2.groups()
  109. data = com.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
  110. elif(back_3):
  111. result = back_3.groups()
  112. data = com.sub('<span style="background:' + result[0] + '">' + result[1] + '</span>', data, 1)
  113. elif(div):
  114. result = div.groups()
  115. data = com.sub('<div style="' + result[0] + '">' + result[1] + '</div>', data, 1)
  116. elif(html):
  117. result = html.groups()
  118. data = com.sub(result[0], data, 1)
  119. elif(fol):
  120. result = fol.groups()
  121. 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)
  122. fol_num += 3
  123. elif(html):
  124. result = html.groups()
  125. data = com.sub(result[0], data, 1)
  126. elif(include_out):
  127. if(include == True):
  128. data = com.sub("", data, 1)
  129. else:
  130. result = include_out.groups()
  131. data = com.sub(result[0], data, 1)
  132. else:
  133. data = com.sub('<code>' + a[0] + '</code>', data, 1)
  134. else:
  135. break
  136. while(True):
  137. com = re.compile("<code>(((?!<\/code>).)*)<\/code>", re.DOTALL)
  138. y = com.search(data)
  139. if(y):
  140. a = y.groups()
  141. mid_data = re.sub("<\/span>", "}}}", a[0])
  142. mid_data = re.sub("<\/div>", "}}}", mid_data)
  143. mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
  144. mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
  145. mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
  146. mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
  147. mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style=&quot;\g<in>&quot;\n", mid_data)
  148. mid_data = re.sub("(?P<in>.)", "<span>\g<in></span>", mid_data)
  149. data = com.sub(mid_data, data, 1)
  150. else:
  151. break
  152. data = re.sub("<span>&</span><span>l</span><span>t</span><span>;</span>", "<span>&lt;</span>", data)
  153. data = re.sub("<span>&</span><span>g</span><span>t</span><span>;</span>", "<span>&gt;</span>", data)
  154. return (data, fol_num)
  155. def backlink_plus(name, link, backtype):
  156. db_ex("select title from back where title = '" + db_pas(link) + "' and link = '" + db_pas(name) + "' and type = '" + backtype + "'")
  157. y = db_get()
  158. if(not y):
  159. db_ex("insert into back (title, link, type) value ('" + db_pas(link) + "', '" + db_pas(name) + "', '" + backtype + "')")
  160. db_com()
  161. def cat_plus(name, link):
  162. db_ex("select title from cat where title = '" + db_pas(link) + "' and cat = '" + db_pas(name) + "'")
  163. y = db_get()
  164. if(not y):
  165. db_ex("insert into cat (title, cat) value ('" + db_pas(link) + "', '" + db_pas(name) + "')")
  166. db_com()
  167. def namumark(title, data):
  168. data = html_pas(data, 1)
  169. b = 0
  170. a = mid_pas(data, b, False)
  171. data = a[0]
  172. b = a[1]
  173. data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
  174. data = savemark(data)
  175. i = 1
  176. while(True):
  177. m = re.search("\n((?:(?:#\s?(?:[^\n]*))\n?)+)", data)
  178. if(m):
  179. result = m.groups()
  180. test = result[0]
  181. while(True):
  182. if(re.search("(?:#\s?(?:[^\n]*))", test)):
  183. test = re.sub("(?:#\s?(?P<in>[^\n]*))", str(i) + ". \g<in>", test, 1)
  184. else:
  185. break
  186. i += 1
  187. data = re.sub("\n((?:(?:#\s?(?:[^\n]*))\n?)+)", '\n' + test, data, 1)
  188. i = 1
  189. else:
  190. break
  191. while(True):
  192. m = re.search("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", data)
  193. if(m):
  194. results = m.groups()
  195. if(results[0] == title):
  196. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "<b>" + results[0] + "</b>", data, 1)
  197. else:
  198. db_ex("select * from data where title = '" + db_pas(results[0]) + "'")
  199. in_con = db_get()
  200. backlink_plus(title, results[0], 'include')
  201. if(in_con):
  202. in_data = in_con[0]['data']
  203. in_data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "", in_data)
  204. in_data = html_pas(in_data, 1)
  205. in_data = mid_pas(in_data, b, True)[0]
  206. if(results[1]):
  207. a = results[1]
  208. while(True):
  209. g = re.search("([^= ,]*)\=([^,]*)", a)
  210. if(g):
  211. result = g.groups()
  212. in_data = re.sub("@" + result[0] + "@", result[1], in_data)
  213. a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
  214. else:
  215. break
  216. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", '\n#nobr#<div>' + in_data + '</div>\n#nobr#', data, 1)
  217. else:
  218. data = re.sub("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]", "<a class=\"not_thing\" href=\"" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
  219. else:
  220. break
  221. while(True):
  222. m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data)
  223. if(m):
  224. results = m.groups()
  225. aa = re.search("^(.*)(#(?:.*))$", results[0])
  226. if(aa):
  227. results = aa.groups()
  228. 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)
  229. else:
  230. data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(results[0]) + '/from/' + url_pas(title) + '" />', data, 1)
  231. backlink_plus(title, results[0], 'redirect')
  232. else:
  233. break
  234. data = '\n' + data + '\n'
  235. data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
  236. while(True):
  237. m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
  238. if(m):
  239. result = m.groups()
  240. blockquote = result[0]
  241. blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
  242. data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
  243. else:
  244. break
  245. m = re.search('\[목차\]', data)
  246. if(not m):
  247. data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
  248. data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
  249. i = 0
  250. h0c = 0
  251. h1c = 0
  252. h2c = 0
  253. h3c = 0
  254. h4c = 0
  255. h5c = 0
  256. last = 0
  257. span = ''
  258. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  259. while(True):
  260. i = i + 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. h1c = 0
  271. h2c = 0
  272. h3c = 0
  273. h4c = 0
  274. h5c = 0
  275. elif(wiki == 2):
  276. h2c = 0
  277. h3c = 0
  278. h4c = 0
  279. h5c = 0
  280. elif(wiki == 3):
  281. h3c = 0
  282. h4c = 0
  283. h5c = 0
  284. elif(wiki == 4):
  285. h4c = 0
  286. h5c = 0
  287. elif(wiki == 5):
  288. h5c = 0
  289. if(wiki == 1):
  290. h0c += 1
  291. elif(wiki == 2):
  292. h1c += 1
  293. elif(wiki == 3):
  294. h2c += 1
  295. elif(wiki == 4):
  296. h3c += 1
  297. elif(wiki == 5):
  298. h4c += 1
  299. else:
  300. h5c += 1
  301. toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.'
  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) + '">편집</a>]</span></h' + str(wiki) + '>', data, 1);
  324. else:
  325. rtoc = 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\(((?:(?!,|\)\]).)*)(?:,(?:\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("\n( +)", data)
  561. if(b):
  562. result = b.groups()
  563. up = re.sub(' ', '<span id="in"></span>', result[0])
  564. data = re.sub("\n( +)", '<br>' + up, data, 1)
  565. else:
  566. break
  567. a = 1
  568. tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
  569. while(True):
  570. b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data)
  571. if(b):
  572. results = b.groups()
  573. if(results[0]):
  574. c = results[1]
  575. c = re.sub("<(?:[^>]*)>", '', c)
  576. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  577. 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)
  578. else:
  579. c = results[1]
  580. c = re.sub("<(?:[^>]*)>", '', c)
  581. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  582. 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)
  583. a = a + 1
  584. else:
  585. tou = tou + '</div>'
  586. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  587. tou = ""
  588. break
  589. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  590. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  591. data = re.sub("\[각주\]", "<br>" + tou, data)
  592. data = data + tou
  593. if(category):
  594. data = data + '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
  595. data = re.sub("(?:\|\|\r\n)", "#table#<nobr>", data)
  596. while(True):
  597. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  598. if(y):
  599. a = y.groups()
  600. mid_data = re.sub("\|\|", "#table#", a[0])
  601. mid_data = re.sub("\r\n", "<br>", mid_data)
  602. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  603. else:
  604. break
  605. data = re.sub("#table#", "||", data)
  606. data = re.sub("<nobr>", "\r\n", data)
  607. while(True):
  608. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  609. if(m):
  610. results = m.groups()
  611. table = results[0]
  612. while(True):
  613. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  614. if(a):
  615. row = ''
  616. cel = ''
  617. celstyle = ''
  618. rowstyle = ''
  619. alltable = ''
  620. result = a.groups()
  621. if(result[1]):
  622. alltable = 'style="'
  623. celstyle = 'style="'
  624. rowstyle = 'style="'
  625. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  626. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  627. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  628. if(q):
  629. resultss = q.groups()
  630. alltable = alltable + 'width:' + resultss[0] + ';'
  631. if(w):
  632. resultss = w.groups()
  633. alltable = alltable + 'height:' + resultss[0] + ';'
  634. if(e):
  635. resultss = e.groups()
  636. if(resultss[0] == 'right'):
  637. alltable = alltable + 'margin-left:auto;'
  638. elif(resultss[0] == 'center'):
  639. alltable = alltable + 'margin:auto;'
  640. else:
  641. alltable = alltable + 'margin-right:auto;'
  642. ee = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", result[1])
  643. if(ee):
  644. resultss = ee.groups()
  645. if(resultss[0] == 'right'):
  646. alltable = alltable + 'text-align:right;'
  647. elif(resultss[0] == 'center'):
  648. alltable = alltable + 'text-align:center;'
  649. else:
  650. alltable = alltable + 'text-align:left;'
  651. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  652. if(r):
  653. resultss = r.groups()
  654. cel = 'colspan="' + resultss[0] + '"'
  655. else:
  656. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  657. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  658. if(t):
  659. resultss = t.groups()
  660. row = 'rowspan="' + resultss[0] + '"'
  661. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  662. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  663. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  664. if(ba):
  665. resultss = ba.groups()
  666. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  667. elif(bb):
  668. resultss = bb.groups()
  669. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  670. elif(bc):
  671. resultss = bc.groups()
  672. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  673. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  674. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  675. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  676. if(z):
  677. resultss = z.groups()
  678. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  679. elif(x):
  680. resultss = x.groups()
  681. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  682. elif(c):
  683. resultss = c.groups()
  684. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  685. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  686. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  687. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  688. if(aq):
  689. resultss = aq.groups()
  690. alltable = alltable + 'background:' + resultss[0] + ';'
  691. elif(aw):
  692. resultss = aw.groups()
  693. alltable = alltable + 'background:' + resultss[0] + ';'
  694. elif(ae):
  695. resultss = ae.groups()
  696. alltable = alltable + 'background:' + resultss[0] + ';'
  697. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  698. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  699. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  700. if(j):
  701. resultss = j.groups()
  702. celstyle = celstyle + 'background:' + resultss[0] + ';'
  703. elif(k):
  704. resultss = k.groups()
  705. celstyle = celstyle + 'background:' + resultss[0] + ';'
  706. elif(l):
  707. resultss = l.groups()
  708. celstyle = celstyle + 'background:' + resultss[0] + ';'
  709. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  710. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  711. ac = re.search("&lt;(\w+)&gt;", result[1])
  712. if(aa):
  713. resultss = aa.groups()
  714. celstyle = celstyle + 'background:' + resultss[0] + ';'
  715. elif(ab):
  716. resultss = ab.groups()
  717. celstyle = celstyle + 'background:' + resultss[0] + ';'
  718. elif(ac):
  719. resultss = ac.groups()
  720. celstyle = celstyle + 'background:' + resultss[0] + ';'
  721. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  722. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  723. if(qa):
  724. resultss = qa.groups()
  725. celstyle = celstyle + 'width:' + resultss[0] + ';'
  726. if(qb):
  727. resultss = qb.groups()
  728. celstyle = celstyle + 'height:' + resultss[0] + ';'
  729. i = re.search("&lt;\)&gt;", result[1])
  730. o = re.search("&lt;:&gt;", result[1])
  731. p = re.search("&lt;\(&gt;", result[1])
  732. if(i):
  733. celstyle = celstyle + 'text-align:right;'
  734. elif(o):
  735. celstyle = celstyle + 'text-align:center;'
  736. elif(p):
  737. celstyle = celstyle + 'text-align:left;'
  738. alltable = alltable + '"'
  739. celstyle = celstyle + '"'
  740. rowstyle = rowstyle + '"'
  741. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  742. else:
  743. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  744. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  745. else:
  746. break
  747. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  748. while(True):
  749. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  750. if(b):
  751. row = ''
  752. cel = ''
  753. celstyle = ''
  754. rowstyle = ''
  755. result = b.groups()
  756. if(result[1]):
  757. celstyle = 'style="'
  758. rowstyle = 'style="'
  759. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  760. if(r):
  761. resultss = r.groups()
  762. cel = 'colspan="' + resultss[0] + '"'
  763. else:
  764. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  765. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  766. if(t):
  767. resultss = t.groups()
  768. row = 'rowspan="' + resultss[0] + '"'
  769. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  770. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  771. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  772. if(ba):
  773. resultss = ba.groups()
  774. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  775. elif(bb):
  776. resultss = bb.groups()
  777. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  778. elif(bc):
  779. resultss = bc.groups()
  780. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  781. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  782. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  783. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  784. if(j):
  785. resultss = j.groups()
  786. celstyle = celstyle + 'background:' + resultss[0] + ';'
  787. elif(k):
  788. resultss = k.groups()
  789. celstyle = celstyle + 'background:' + resultss[0] + ';'
  790. elif(l):
  791. resultss = l.groups()
  792. celstyle = celstyle + 'background:' + resultss[0] + ';'
  793. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  794. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  795. ac = re.search("&lt;(\w+)&gt;", result[1])
  796. if(aa):
  797. resultss = aa.groups()
  798. celstyle = celstyle + 'background:' + resultss[0] + ';'
  799. elif(ab):
  800. resultss = ab.groups()
  801. celstyle = celstyle + 'background:' + resultss[0] + ';'
  802. elif(ac):
  803. resultss = ac.groups()
  804. celstyle = celstyle + 'background:' + resultss[0] + ';'
  805. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  806. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  807. if(qa):
  808. resultss = qa.groups()
  809. celstyle = celstyle + 'width:' + resultss[0] + ';'
  810. if(qb):
  811. resultss = qb.groups()
  812. celstyle = celstyle + 'height:' + resultss[0] + ';'
  813. i = re.search("&lt;\)&gt;", result[1])
  814. o = re.search("&lt;:&gt;", result[1])
  815. p = re.search("&lt;\(&gt;", result[1])
  816. if(i):
  817. celstyle = celstyle + 'text-align:right;'
  818. elif(o):
  819. celstyle = celstyle + 'text-align:center;'
  820. elif(p):
  821. celstyle = celstyle + 'text-align:left;'
  822. celstyle = celstyle + '"'
  823. rowstyle = rowstyle + '"'
  824. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  825. else:
  826. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  827. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  828. else:
  829. break
  830. while(True):
  831. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  832. if(c):
  833. row = ''
  834. cel = ''
  835. celstyle = ''
  836. result = c.groups()
  837. if(result[1]):
  838. celstyle = 'style="'
  839. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  840. if(r):
  841. resultss = r.groups()
  842. cel = 'colspan="' + resultss[0] + '"';
  843. else:
  844. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  845. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  846. if(t):
  847. resultss = t.groups()
  848. row = 'rowspan="' + resultss[0] + '"';
  849. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  850. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  851. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  852. if(j):
  853. resultss = j.groups()
  854. celstyle = celstyle + 'background:' + resultss[0] + ';'
  855. elif(k):
  856. resultss = k.groups()
  857. celstyle = celstyle + 'background:' + resultss[0] + ';'
  858. elif(l):
  859. resultss = l.groups()
  860. celstyle = celstyle + 'background:' + resultss[0] + ';'
  861. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  862. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  863. ac = re.search("&lt;(\w+)&gt;", result[1])
  864. if(aa):
  865. resultss = aa.groups()
  866. celstyle = celstyle + 'background:' + resultss[0] + ';'
  867. elif(ab):
  868. resultss = ab.groups()
  869. celstyle = celstyle + 'background:' + resultss[0] + ';'
  870. elif(ac):
  871. resultss = ac.groups()
  872. celstyle = celstyle + 'background:' + resultss[0] + ';'
  873. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  874. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  875. if(qa):
  876. resultss = qa.groups()
  877. celstyle = celstyle + 'width:' + resultss[0] + ';'
  878. if(qb):
  879. resultss = qb.groups()
  880. celstyle = celstyle + 'height:' + resultss[0] + ';'
  881. i = re.search("&lt;\)&gt;", result[1])
  882. o = re.search("&lt;:&gt;", result[1])
  883. p = re.search("&lt;\(&gt;", result[1])
  884. if(i):
  885. celstyle = celstyle + 'text-align:right;'
  886. elif(o):
  887. celstyle = celstyle + 'text-align:center;'
  888. elif(p):
  889. celstyle = celstyle + 'text-align:left;'
  890. celstyle = celstyle + '"'
  891. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  892. else:
  893. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  894. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  895. else:
  896. break
  897. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  898. else:
  899. break
  900. data = re.sub("(\n#nobr#|#nobr#\n|#nobr#)", "", data)
  901. data = re.sub('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
  902. data = re.sub('\n', '<br>', data)
  903. data = re.sub('^<br>', '', data)
  904. return data