mark.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  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(data):
  14. data = re.sub("\[date\(now\)\]", get_time(), data)
  15. if(not re.search("\.", ip_check())):
  16. name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
  17. else:
  18. name = ip_check()
  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. 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(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(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
  254. h0c = 0
  255. h1c = 0
  256. h2c = 0
  257. h3c = 0
  258. h4c = 0
  259. h5c = 0
  260. last = 0
  261. span = ''
  262. rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
  263. while(True):
  264. i = i + 1
  265. m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
  266. if(m):
  267. result = m.groups()
  268. wiki = len(result[0])
  269. if(last < wiki):
  270. last = wiki
  271. else:
  272. last = wiki
  273. if(wiki == 1):
  274. h1c = 0
  275. h2c = 0
  276. h3c = 0
  277. h4c = 0
  278. h5c = 0
  279. elif(wiki == 2):
  280. h2c = 0
  281. h3c = 0
  282. h4c = 0
  283. h5c = 0
  284. elif(wiki == 3):
  285. h3c = 0
  286. h4c = 0
  287. h5c = 0
  288. elif(wiki == 4):
  289. h4c = 0
  290. h5c = 0
  291. elif(wiki == 5):
  292. h5c = 0
  293. if(wiki == 1):
  294. h0c += 1
  295. elif(wiki == 2):
  296. h1c += 1
  297. elif(wiki == 3):
  298. h2c += 1
  299. elif(wiki == 4):
  300. h3c += 1
  301. elif(wiki == 5):
  302. h4c += 1
  303. else:
  304. h5c += 1
  305. toc = str(h0c) + '.' + str(h1c) + '.' + str(h2c) + '.' + str(h3c) + '.' + str(h4c) + '.' + str(h5c) + '.'
  306. toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
  307. toc = re.sub("0\.", '', toc)
  308. toc = re.sub("#\.", '.', toc)
  309. toc = re.sub("\.$", '', toc)
  310. test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
  311. if(test):
  312. g = test.groups()
  313. if(g[4]):
  314. span = '<span id="out"></span>' * 4
  315. elif(g[3]):
  316. span = '<span id="out"></span>' * 3
  317. elif(g[2]):
  318. span = '<span id="out"></span>' * 2
  319. elif(g[1]):
  320. span = '<span id="out"></span>'
  321. else:
  322. span = ''
  323. rtoc = rtoc + span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
  324. c = re.sub(" $", "", result[1])
  325. d = c
  326. c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
  327. 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);
  328. else:
  329. rtoc = rtoc + '</div>'
  330. break
  331. data = re.sub("\[목차\]", rtoc, data)
  332. category = ''
  333. while(True):
  334. m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
  335. if(m):
  336. g = m.groups()
  337. if(not title == g[0]):
  338. cat_plus(title, g[0])
  339. if(category == ''):
  340. db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
  341. exists = db_get()
  342. if(exists):
  343. red = ""
  344. else:
  345. red = 'class="not_thing"'
  346. category = category + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  347. else:
  348. db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
  349. exists = db_get()
  350. if(exists):
  351. red = ""
  352. else:
  353. red = 'class="not_thing"'
  354. category = category + ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
  355. data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
  356. else:
  357. break
  358. data = re.sub("'''(?P<in>.+?)'''(?!')", '<b>\g<in></b>', data)
  359. data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
  360. data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
  361. data = re.sub('--(?P<in>.+?)--(?!-)', '<s>\g<in></s>', data)
  362. data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
  363. data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
  364. data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
  365. data = re.sub('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '$\g<in>$', data)
  366. data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
  367. data = re.sub('\[ruby\((?P<in>[^\|]*)\|(?P<out>[^\)]*)\)\]', '<ruby>\g<in><rp>(</rp><rt>\g<out></rt><rp>)</rp></ruby>', data)
  368. data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data)
  369. while(True):
  370. m = re.search("\[\[파일:((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
  371. if(m):
  372. c = m.groups()
  373. if(c):
  374. if(not re.search("^파일:([^\n]*)", title)):
  375. backlink_plus(title, '파일:' + c[0], 'file')
  376. if(c[1]):
  377. n = re.search("width=([^ \n&]*)", c[1])
  378. e = re.search("height=([^ \n&]*)", c[1])
  379. if(n):
  380. a = n.groups()
  381. width = a[0]
  382. else:
  383. width = ''
  384. if(e):
  385. b = e.groups()
  386. height = b[0]
  387. else:
  388. height = ''
  389. try:
  390. extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
  391. img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
  392. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + extension[0] + img + '"><img src="/image/' + sha224(extension[0]) + img + '" width="' + width + '" height="' + height + '"></a>', data, 1)
  393. except:
  394. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
  395. else:
  396. try:
  397. extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
  398. img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
  399. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<a href='/w/파일:" + extension[0] + img + "'><img src='/image/" + sha224(extension[0]) + img + "'></a>", data, 1)
  400. except:
  401. data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
  402. else:
  403. break
  404. else:
  405. break
  406. data = re.sub("\[br\]",'<br>', data)
  407. while(True):
  408. com = re.compile("\[youtube\((?:https:\/\/www\.youtube\.com\/watch\?v=|https:\/\/youtu\.be\/)?((?:(?!,|\)\]).)*)(?:,(?:\s)?)?(?:width=((?:(?!,|\)\]).)*))?(?:,(?:\s)?)?(?:height=((?:(?!,|\)\]).)*))?\)\]")
  409. m = com.search(data)
  410. if(m):
  411. result = m.groups()
  412. if(result[1]):
  413. if(result[2]):
  414. width = result[1]
  415. height = result[2]
  416. else:
  417. width = result[1]
  418. height = '315'
  419. elif(result[2]):
  420. height = result[2]
  421. width = '560'
  422. else:
  423. width = '560'
  424. height = '315'
  425. data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + result[0] + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
  426. else:
  427. break
  428. data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
  429. while(True):
  430. m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
  431. if(m):
  432. result = m.groups()
  433. a = re.search("((?:(?!\|).)*)\|(.*)", result[0])
  434. if(a):
  435. results = a.groups()
  436. aa = re.search("^(.*)(#(?:.*))$", results[0])
  437. if(aa):
  438. g = results[1]
  439. results = aa.groups()
  440. b = re.search("^http(?:s)?:\/\/", results[0])
  441. if(b):
  442. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + results[1] + '">' + g + '</a>', data, 1)
  443. else:
  444. if(results[0] == title):
  445. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
  446. else:
  447. db_ex("select title from data where title = '" + db_pas(results[0]) + "'")
  448. y = db_get()
  449. if(y):
  450. clas = ''
  451. else:
  452. clas = 'not_thing'
  453. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + results[1] + '" class="' + clas + '" href="/w/' + url_pas(results[0]) + results[1] + '">' + g + '</a>', data, 1)
  454. backlink_plus(title, results[0], '')
  455. else:
  456. b = re.search("^http(?:s)?:\/\/", results[0])
  457. if(b):
  458. c = re.search("(?:\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg])", results[0])
  459. if(c):
  460. img = results[0]
  461. img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", img)
  462. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + results[1] + '</a>', data, 1)
  463. else:
  464. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + '">' + results[1] + '</a>', data, 1)
  465. else:
  466. if(results[0] == title):
  467. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + results[1] + '</b>', data, 1)
  468. else:
  469. db_ex("select title from data where title = '" + db_pas(results[0]) + "'")
  470. y = db_get()
  471. if(y):
  472. clas = ''
  473. else:
  474. clas = 'not_thing'
  475. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + results[0] + '" class="' + clas + '" href="/w/' + url_pas(results[0]) + '">' + results[1] + '</a>', data, 1)
  476. backlink_plus(title, results[0], '')
  477. else:
  478. aa = re.search("^(.*)(#(?:.*))$", result[0])
  479. if(aa):
  480. result = aa.groups()
  481. b = re.search("^http(?:s)?:\/\/", result[0])
  482. if(b):
  483. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + result[0] + result[1] + '">' + result[0] + result[1] + '</a>', data, 1)
  484. else:
  485. if(result[0] == title):
  486. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + result[0] + result[1] + '</b>', data, 1)
  487. else:
  488. db_ex("select title from data where title = '" + db_pas(result[0]) + "'")
  489. y = db_get()
  490. if(y):
  491. clas = ''
  492. else:
  493. clas = 'not_thing'
  494. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a href="/w/' + url_pas(result[0]) + result[1] + '" class="' + clas + '">' + result[0] + result[1] + '</a>', data, 1)
  495. backlink_plus(title, result[0], '')
  496. else:
  497. b = re.search("^http(?:s)?:\/\/", result[0])
  498. if(b):
  499. c = re.search("(?:\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg])", result[0])
  500. if(c):
  501. img = result[0]
  502. img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", img)
  503. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + '">' + img + '</a>', data, 1)
  504. else:
  505. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + result[0] + '">' + result[0] + '</a>', data, 1)
  506. else:
  507. if(result[0] == title):
  508. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + result[0] + '</b>', data, 1)
  509. else:
  510. db_ex("select title from data where title = '" + db_pas(result[0]) + "'")
  511. y = db_get()
  512. if(y):
  513. clas = ''
  514. else:
  515. clas = 'not_thing'
  516. data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a href="/w/' + url_pas(result[0]) + '" class="' + clas + '">' + result[0] + '</a>', data, 1)
  517. backlink_plus(title, result[0], '')
  518. else:
  519. break
  520. while(True):
  521. 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|%)?))?)")
  522. m = com.search(data)
  523. if(m):
  524. result = m.groups()
  525. if(result[1]):
  526. if(result[2]):
  527. width = result[1]
  528. height = result[2]
  529. else:
  530. width = result[1]
  531. height = ''
  532. elif(result[2]):
  533. height = result[2]
  534. width = ''
  535. else:
  536. width = ''
  537. height = ''
  538. c = result[0]
  539. c = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", c)
  540. data = com.sub("<img width='" + width + "' height='" + height + "' src='" + c + "'>", data, 1)
  541. else:
  542. break
  543. while(True):
  544. m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
  545. if(m):
  546. result = m.groups()
  547. end = str(result[0])
  548. while(True):
  549. isspace = re.search("( +)\*\s([^\n]*)", end)
  550. if(isspace):
  551. spacebar = isspace.groups()
  552. up = len(spacebar[0]) * 20
  553. end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
  554. else:
  555. break
  556. end = re.sub("\n", '', end)
  557. data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
  558. else:
  559. break
  560. data = re.sub('\[date\]', get_time(), data)
  561. data = re.sub("#(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])#", ".\g<in>", data)
  562. data = re.sub("-{4,11}", "<hr>", data)
  563. while(True):
  564. b = re.search("(<\/h[0-9]>|\n)( +)", data)
  565. if(b):
  566. result = b.groups()
  567. up = re.sub(' ', '<span id="in"></span>', result[1])
  568. if(re.search('<\/h[0-9]>', result[0])):
  569. data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
  570. else:
  571. data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
  572. else:
  573. break
  574. a = 1
  575. tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
  576. while(True):
  577. b = re.search("\[\*([^\s]*)\s(((?!\]).)*)\]", data)
  578. if(b):
  579. results = b.groups()
  580. if(results[0]):
  581. c = results[1]
  582. c = re.sub("<(?:[^>]*)>", '', c)
  583. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
  584. 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)
  585. else:
  586. c = results[1]
  587. c = re.sub("<(?:[^>]*)>", '', c)
  588. tou = tou + "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
  589. 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)
  590. a = a + 1
  591. else:
  592. tou = tou + '</div>'
  593. if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
  594. tou = ""
  595. break
  596. data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
  597. data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
  598. data = re.sub("\[각주\]", "<br>" + tou, data)
  599. data = data + tou
  600. if(category):
  601. data = data + '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
  602. data = re.sub("(?:\|\|\r\n)", "#table#<nobr>", data)
  603. while(True):
  604. y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
  605. if(y):
  606. a = y.groups()
  607. mid_data = re.sub("\|\|", "#table#", a[0])
  608. mid_data = re.sub("\r\n", "<br>", mid_data)
  609. data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
  610. else:
  611. break
  612. data = re.sub("#table#", "||", data)
  613. data = re.sub("<nobr>", "\r\n", data)
  614. while(True):
  615. m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
  616. if(m):
  617. results = m.groups()
  618. table = results[0]
  619. while(True):
  620. a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  621. if(a):
  622. row = ''
  623. cel = ''
  624. celstyle = ''
  625. rowstyle = ''
  626. alltable = ''
  627. result = a.groups()
  628. if(result[1]):
  629. alltable = 'style="'
  630. celstyle = 'style="'
  631. rowstyle = 'style="'
  632. q = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", result[1])
  633. w = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", result[1])
  634. e = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", result[1])
  635. if(q):
  636. resultss = q.groups()
  637. alltable = alltable + 'width:' + resultss[0] + ';'
  638. if(w):
  639. resultss = w.groups()
  640. alltable = alltable + 'height:' + resultss[0] + ';'
  641. if(e):
  642. resultss = e.groups()
  643. if(resultss[0] == 'right'):
  644. alltable = alltable + 'margin-left:auto;'
  645. elif(resultss[0] == 'center'):
  646. alltable = alltable + 'margin:auto;'
  647. else:
  648. alltable = alltable + 'margin-right:auto;'
  649. ee = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", result[1])
  650. if(ee):
  651. resultss = ee.groups()
  652. if(resultss[0] == 'right'):
  653. alltable = alltable + 'text-align:right;'
  654. elif(resultss[0] == 'center'):
  655. alltable = alltable + 'text-align:center;'
  656. else:
  657. alltable = alltable + 'text-align:left;'
  658. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  659. if(r):
  660. resultss = r.groups()
  661. cel = 'colspan="' + resultss[0] + '"'
  662. else:
  663. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  664. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  665. if(t):
  666. resultss = t.groups()
  667. row = 'rowspan="' + resultss[0] + '"'
  668. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  669. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  670. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  671. if(ba):
  672. resultss = ba.groups()
  673. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  674. elif(bb):
  675. resultss = bb.groups()
  676. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  677. elif(bc):
  678. resultss = bc.groups()
  679. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  680. z = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  681. x = re.search("&lt;table\s?bordercolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  682. c = re.search("&lt;table\s?bordercolor=(\w+)&gt;", result[1])
  683. if(z):
  684. resultss = z.groups()
  685. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  686. elif(x):
  687. resultss = x.groups()
  688. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  689. elif(c):
  690. resultss = c.groups()
  691. alltable = alltable + 'border:' + resultss[0] + ' 2px solid;'
  692. aq = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  693. aw = re.search("&lt;table\s?bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  694. ae = re.search("&lt;table\s?bgcolor=(\w+)&gt;", result[1])
  695. if(aq):
  696. resultss = aq.groups()
  697. alltable = alltable + 'background:' + resultss[0] + ';'
  698. elif(aw):
  699. resultss = aw.groups()
  700. alltable = alltable + 'background:' + resultss[0] + ';'
  701. elif(ae):
  702. resultss = ae.groups()
  703. alltable = alltable + 'background:' + resultss[0] + ';'
  704. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  705. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  706. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  707. if(j):
  708. resultss = j.groups()
  709. celstyle = celstyle + 'background:' + resultss[0] + ';'
  710. elif(k):
  711. resultss = k.groups()
  712. celstyle = celstyle + 'background:' + resultss[0] + ';'
  713. elif(l):
  714. resultss = l.groups()
  715. celstyle = celstyle + 'background:' + resultss[0] + ';'
  716. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  717. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  718. ac = re.search("&lt;(\w+)&gt;", result[1])
  719. if(aa):
  720. resultss = aa.groups()
  721. celstyle = celstyle + 'background:' + resultss[0] + ';'
  722. elif(ab):
  723. resultss = ab.groups()
  724. celstyle = celstyle + 'background:' + resultss[0] + ';'
  725. elif(ac):
  726. resultss = ac.groups()
  727. celstyle = celstyle + 'background:' + resultss[0] + ';'
  728. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  729. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  730. if(qa):
  731. resultss = qa.groups()
  732. celstyle = celstyle + 'width:' + resultss[0] + ';'
  733. if(qb):
  734. resultss = qb.groups()
  735. celstyle = celstyle + 'height:' + resultss[0] + ';'
  736. i = re.search("&lt;\)&gt;", result[1])
  737. o = re.search("&lt;:&gt;", result[1])
  738. p = re.search("&lt;\(&gt;", result[1])
  739. if(i):
  740. celstyle = celstyle + 'text-align:right;'
  741. elif(o):
  742. celstyle = celstyle + 'text-align:center;'
  743. elif(p):
  744. celstyle = celstyle + 'text-align:left;'
  745. alltable = alltable + '"'
  746. celstyle = celstyle + '"'
  747. rowstyle = rowstyle + '"'
  748. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  749. else:
  750. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  751. table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
  752. else:
  753. break
  754. table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
  755. while(True):
  756. b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  757. if(b):
  758. row = ''
  759. cel = ''
  760. celstyle = ''
  761. rowstyle = ''
  762. result = b.groups()
  763. if(result[1]):
  764. celstyle = 'style="'
  765. rowstyle = 'style="'
  766. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  767. if(r):
  768. resultss = r.groups()
  769. cel = 'colspan="' + resultss[0] + '"'
  770. else:
  771. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  772. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  773. if(t):
  774. resultss = t.groups()
  775. row = 'rowspan="' + resultss[0] + '"'
  776. ba = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  777. bb = re.search("&lt;rowbgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  778. bc = re.search("&lt;rowbgcolor=(\w+)&gt;", result[1])
  779. if(ba):
  780. resultss = ba.groups()
  781. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  782. elif(bb):
  783. resultss = bb.groups()
  784. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  785. elif(bc):
  786. resultss = bc.groups()
  787. rowstyle = rowstyle + 'background:' + resultss[0] + ';'
  788. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  789. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  790. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  791. if(j):
  792. resultss = j.groups()
  793. celstyle = celstyle + 'background:' + resultss[0] + ';'
  794. elif(k):
  795. resultss = k.groups()
  796. celstyle = celstyle + 'background:' + resultss[0] + ';'
  797. elif(l):
  798. resultss = l.groups()
  799. celstyle = celstyle + 'background:' + resultss[0] + ';'
  800. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  801. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  802. ac = re.search("&lt;(\w+)&gt;", result[1])
  803. if(aa):
  804. resultss = aa.groups()
  805. celstyle = celstyle + 'background:' + resultss[0] + ';'
  806. elif(ab):
  807. resultss = ab.groups()
  808. celstyle = celstyle + 'background:' + resultss[0] + ';'
  809. elif(ac):
  810. resultss = ac.groups()
  811. celstyle = celstyle + 'background:' + resultss[0] + ';'
  812. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  813. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  814. if(qa):
  815. resultss = qa.groups()
  816. celstyle = celstyle + 'width:' + resultss[0] + ';'
  817. if(qb):
  818. resultss = qb.groups()
  819. celstyle = celstyle + 'height:' + resultss[0] + ';'
  820. i = re.search("&lt;\)&gt;", result[1])
  821. o = re.search("&lt;:&gt;", result[1])
  822. p = re.search("&lt;\(&gt;", result[1])
  823. if(i):
  824. celstyle = celstyle + 'text-align:right;'
  825. elif(o):
  826. celstyle = celstyle + 'text-align:center;'
  827. elif(p):
  828. celstyle = celstyle + 'text-align:left;'
  829. celstyle = celstyle + '"'
  830. rowstyle = rowstyle + '"'
  831. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  832. else:
  833. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  834. table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
  835. else:
  836. break
  837. while(True):
  838. c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
  839. if(c):
  840. row = ''
  841. cel = ''
  842. celstyle = ''
  843. result = c.groups()
  844. if(result[1]):
  845. celstyle = 'style="'
  846. r = re.search("&lt;-((?:(?!&gt;).)*)&gt;", result[1])
  847. if(r):
  848. resultss = r.groups()
  849. cel = 'colspan="' + resultss[0] + '"';
  850. else:
  851. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  852. t = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", result[1])
  853. if(t):
  854. resultss = t.groups()
  855. row = 'rowspan="' + resultss[0] + '"';
  856. j = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{6})&gt;", result[1])
  857. k = re.search("&lt;bgcolor=(#[0-9a-f-A-F]{3})&gt;", result[1])
  858. l = re.search("&lt;bgcolor=(\w+)&gt;", result[1])
  859. if(j):
  860. resultss = j.groups()
  861. celstyle = celstyle + 'background:' + resultss[0] + ';'
  862. elif(k):
  863. resultss = k.groups()
  864. celstyle = celstyle + 'background:' + resultss[0] + ';'
  865. elif(l):
  866. resultss = l.groups()
  867. celstyle = celstyle + 'background:' + resultss[0] + ';'
  868. aa = re.search("&lt;(#[0-9a-f-A-F]{6})&gt;", result[1])
  869. ab = re.search("&lt;(#[0-9a-f-A-F]{3})&gt;", result[1])
  870. ac = re.search("&lt;(\w+)&gt;", result[1])
  871. if(aa):
  872. resultss = aa.groups()
  873. celstyle = celstyle + 'background:' + resultss[0] + ';'
  874. elif(ab):
  875. resultss = ab.groups()
  876. celstyle = celstyle + 'background:' + resultss[0] + ';'
  877. elif(ac):
  878. resultss = ac.groups()
  879. celstyle = celstyle + 'background:' + resultss[0] + ';'
  880. qa = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", result[1])
  881. qb = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", result[1])
  882. if(qa):
  883. resultss = qa.groups()
  884. celstyle = celstyle + 'width:' + resultss[0] + ';'
  885. if(qb):
  886. resultss = qb.groups()
  887. celstyle = celstyle + 'height:' + resultss[0] + ';'
  888. i = re.search("&lt;\)&gt;", result[1])
  889. o = re.search("&lt;:&gt;", result[1])
  890. p = re.search("&lt;\(&gt;", result[1])
  891. if(i):
  892. celstyle = celstyle + 'text-align:right;'
  893. elif(o):
  894. celstyle = celstyle + 'text-align:center;'
  895. elif(p):
  896. celstyle = celstyle + 'text-align:left;'
  897. celstyle = celstyle + '"'
  898. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
  899. else:
  900. cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
  901. table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
  902. else:
  903. break
  904. data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
  905. else:
  906. break
  907. data = re.sub("(\n#nobr#|#nobr#\n|#nobr#)", "", data)
  908. data = re.sub('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
  909. data = re.sub('\n', '<br>', data)
  910. data = re.sub('^<br>', '', data)
  911. return data