mark.py 49 KB

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