| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047 |
- from func import *
- json_data = open('set.json').read()
- set_data = json.loads(json_data)
- conn = pymysql.connect(host = set_data['host'], user = set_data['user'], password = set_data['pw'], charset = 'utf8mb4')
- curs = conn.cursor(pymysql.cursors.DictCursor)
- def db_com():
- return(conn.commit())
-
- def db_get():
- return(curs.fetchall())
-
- db_ex = curs.execute
- db_pas = pymysql.escape_string
- db_ex("use " + set_data['db'])
- def savemark(data):
- data = re.sub("\[date\(now\)\]", get_time(), data)
-
- if(not re.search("\.", ip_check())):
- name = '[[사용자:' + ip_check() + '|' + ip_check() + ']]'
- else:
- name = ip_check()
-
- data = re.sub("\[name\]", name, data)
- return(data)
- def html_pas(data, how):
- data = re.sub("%phtml%(?P<in>(?:\/)?(?:a|div|span|embed|iframe)(?:\s[^%]*)?)%phtml%", "<\g<in>>", data)
- while(True):
- if(how == 1):
- y = re.search("<((a|div|span|embed|iframe)(?:\s[^>]*))>", data)
- else:
- y = re.search("<((a)(?:\s[^>]*))>", data)
-
- if(y):
- b = y.groups()
- if(re.search("<(\/" + b[1] + ")>", data)):
- xss_test = re.search('src=(?:"|\')?(http(s)?:\/\/([^\/]*)\/(?:[^"\' ]*))(?:"|\')?', b[0])
-
- if(xss_test):
- check = xss_test.groups()
-
- if(check[2] == "www.youtube.com" or check[2] == "serviceapi.nmv.naver.com" or check[2] == "tv.kakao.com" or check[2] == "tvple.com"):
- a = b[0]
- else:
- a = re.sub('src=(?:"|\')([^"\']*)(?:"|\')', '', b[0])
- else:
- a = b[0]
-
- a = re.sub('(?:"|\')', '#.#', a)
- try:
- if(not check[1] == None):
- data = re.sub("<((?:\/)?" + b[1] + "(?:\s[^>]*))>", "%phtml%" + a + "%phtml%", data, 1)
- data = re.sub("<\/" + b[1] + ">", "%phtml%/" + b[1] + "%phtml%", data, 1)
- else:
- data = re.sub("<((?:\/)?" + b[1] + "(?:\s[^>]*))>", "[[" + check[0] + "]]", data, 1)
- data = re.sub("<\/" + b[1] + ">", "", data, 1)
- except:
- data = re.sub("<((?:\/)?" + b[1] + "(?:\s[^>]*))>", "%phtml%" + a + "%phtml%", data, 1)
- data = re.sub("<\/" + b[1] + ">", "%phtml%/" + b[1] + "%phtml%", data, 1)
- else:
- data = re.sub("<((?:\/)?" + b[1] + "(?:\s[^>]*))>", '<' + b[0] + '>', data, 1)
-
- break
- else:
- break
- data = re.sub('<', '<', data)
- data = re.sub('>', '>', data)
- data = re.sub('"', '"', data)
-
- data = re.sub("%phtml%(?P<in>(?:\/)?(?:a|div|span|embed|iframe)(?:\s[^%]*)?)%phtml%", "<\g<in>>", data)
- data = re.sub('#.#', '"', data)
- return(data)
-
- def mid_pas(data, fol_num, include):
- while(True):
- com = re.compile("{{{((?:(?!{{{)(?!}}}).)*)}}}", re.DOTALL)
- y = com.search(data)
-
- if(y):
- a = y.groups()
-
- big_a = re.compile("^\+([1-5])\s(.*)$", re.DOTALL)
- big = big_a.search(a[0])
-
- small_a = re.compile("^\-([1-5])\s(.*)$", re.DOTALL)
- small = small_a.search(a[0])
-
- color_a = re.compile("^(#[0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
- color = color_a.search(a[0])
-
- color_b = re.compile("^(#[0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
- color_2 = color_b.search(a[0])
-
- color_c = re.compile("^#(\w+)\s(.*)$", re.DOTALL)
- color_3 = color_c.search(a[0])
-
- back_a = re.compile("^@([0-9a-f-A-F]{6})\s(.*)$", re.DOTALL)
- back = back_a.search(a[0])
-
- back_b = re.compile("^@([0-9a-f-A-F]{3})\s(.*)$", re.DOTALL)
- back_2 = back_b.search(a[0])
-
- back_c = re.compile("^@(\w+)\s(.*)$", re.DOTALL)
- back_3 = back_c.search(a[0])
-
- include_out_a = re.compile("^#!noin\s(.*)$", re.DOTALL)
- include_out = include_out_a.search(a[0])
-
- div_a = re.compile("^#!wiki\sstyle="((?:(?!"|\n).)*)"\n?\s\n(.*)$", re.DOTALL)
- div = div_a.search(a[0])
-
- html_a = re.compile("^#!html\s(.*)$", re.DOTALL)
- html = html_a.search(a[0])
-
- fol_a = re.compile("^#!folding\s((?:(?!\n).)*)\n?\s\n(.*)$", re.DOTALL)
- fol = fol_a.search(a[0])
-
- syn_a = re.compile("^#!syntax\s([^\n]*)\r\n(.*)$", re.DOTALL)
- syn = syn_a.search(a[0])
-
- if(big):
- result = big.groups()
- data = com.sub('<span class="font-size-' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(small):
- result = small.groups()
- data = com.sub('<span class="font-size-small-' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(color):
- result = color.groups()
- data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(color_2):
- result = color_2.groups()
- data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(color_3):
- result = color_3.groups()
- data = com.sub('<span style="color:' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(back):
- result = back.groups()
- data = com.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(back_2):
- result = back_2.groups()
- data = com.sub('<span style="background:#' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(back_3):
- result = back_3.groups()
- data = com.sub('<span style="background:' + result[0] + '">' + result[1] + '</span>', data, 1)
- elif(div):
- result = div.groups()
- data = com.sub('<div style="' + result[0] + '">' + result[1] + '</div>', data, 1)
- elif(html):
- result = html.groups()
- data = com.sub(result[0], data, 1)
- elif(fol):
- result = fol.groups()
- 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)
-
- fol_num += 3
- elif(syn):
- result = syn.groups()
- data = com.sub('<pre id="syntax"><code class="' + result[0] + '">' + re.sub(' ', '<space>', result[1]) + '</code></pre>', data, 1)
- elif(html):
- result = html.groups()
- data = com.sub(result[0], data, 1)
- elif(include_out):
- if(include == True):
- data = com.sub("", data, 1)
- else:
- result = include_out.groups()
- data = com.sub(result[0], data, 1)
- else:
- data = com.sub('<code>' + a[0] + '</code>', data, 1)
- else:
- break
-
- while(True):
- com = re.compile("<code>(((?!<\/code>).)*)<\/code>", re.DOTALL)
- y = com.search(data)
- if(y):
- a = y.groups()
-
- mid_data = re.sub("<\/span>", "}}}", a[0])
- mid_data = re.sub("<\/div>", "}}}", mid_data)
- mid_data = re.sub('<span class="font\-size\-(?P<in>[1-6])">', "{{{+\g<in> ", mid_data)
- mid_data = re.sub('<span class="font\-size\-small\-(?P<in>[1-6])">', "{{{-\g<in> ", mid_data)
- mid_data = re.sub('<span style="color:(?:#)?(?P<in>[^"]*)">', "{{{#\g<in> ", mid_data)
- mid_data = re.sub('<span style="background:(?:#)?(?P<in>[^"]*)">', "{{{@\g<in> ", mid_data)
- mid_data = re.sub('<div style="(?P<in>[^"]*)">', "{{{#!wiki style="\g<in>"\n", mid_data)
- mid_data = re.sub("(?P<in>.)", "<nowiki>\g<in></nowiki>", mid_data)
-
- data = com.sub(mid_data, data, 1)
- else:
- break
-
- return((data, fol_num))
- def backlink_plus(name, link, backtype):
- db_ex("select title from back where title = '" + db_pas(link) + "' and link = '" + db_pas(name) + "' and type = '" + backtype + "'")
- y = db_get()
- if(not y):
- db_ex("insert into back (title, link, type) value ('" + db_pas(link) + "', '" + db_pas(name) + "', '" + backtype + "')")
- db_com()
- def cat_plus(name, link):
- db_ex("select title from cat where title = '" + db_pas(link) + "' and cat = '" + db_pas(name) + "'")
- y = db_get()
- if(not y):
- db_ex("insert into cat (title, cat) value ('" + db_pas(link) + "', '" + db_pas(name) + "')")
- db_com()
- def namumark(title, data):
- data = html_pas(data, 1)
- b = 0
- a = mid_pas(data, b, False)
-
- data = a[0]
- b = a[1]
-
- data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)
- data = savemark(data)
-
- data = '\n' + data + '\n'
-
- include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:,\s?(?:[^)]*))+)?\)\]")
- while(True):
- m = include.search(data)
- if(m):
- results = m.groups()
- if(results[0] == title):
- data = include.sub("<b>" + results[0] + "</b>", data, 1)
- else:
- db_ex("select * from data where title = '" + db_pas(results[0]) + "'")
- in_con = db_get()
-
- backlink_plus(title, results[0], 'include')
- if(in_con):
- in_data = in_con[0]['data']
- in_data = include.sub("", in_data)
-
- in_data = html_pas(in_data, 1)
- in_data = mid_pas(in_data, b, True)[0]
-
- if(results[1]):
- a = results[1]
- while(True):
- g = re.search("([^= ,]*)\=([^,]*)", a)
- if(g):
- result = g.groups()
- in_data = re.sub("@" + result[0] + "@", result[1], in_data)
- a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
- else:
- break
-
- data = include.sub('\n<nobr><div>' + in_data + '</div><nobr>\n', data, 1)
- else:
- data = include.sub("<a class=\"not_thing\" href=\"" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
- else:
- break
-
- while(True):
- m = re.search('^#(?:redirect|넘겨주기)\s([^\n]*)', data)
- if(m):
- results = m.groups()
- aa = re.search("^(.*)(#(?:.*))$", results[0])
- if(aa):
- results = aa.groups()
- 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)
- else:
- data = re.sub('^#(?:redirect|넘겨주기)\s([^\n]*)', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(results[0]) + '/from/' + url_pas(title) + '" />', data, 1)
-
- backlink_plus(title, results[0], 'redirect')
- else:
- break
- data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", data)
-
- while(True):
- m = re.search("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", data)
- if(m):
- result = m.groups()
- blockquote = result[0]
- blockquote = re.sub("\n>\s?", "\n", blockquote)
- data = re.sub("\n>\s?((?:[^\n]*)(?:(?:(?:(?:\n>\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
- else:
- break
-
- if(not re.search('\[목차\]', data)):
- if(not re.search('\[목차\(없음\)\]', data)):
- data = re.sub("(?P<in>(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "[목차]\n\g<in>", data, 1)
- else:
- data = re.sub("\[목차\(없음\)\]", "", data)
-
- data = re.sub("(\n)(?P<in>\r\n(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n)", "\g<in>", data)
-
- i = [0, 0, 0, 0, 0, 0, 0]
- last = 0
- span = ''
- rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
- while(True):
- i[0] += 1
- m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', data)
- if(m):
- result = m.groups()
- wiki = len(result[0])
- if(last < wiki):
- last = wiki
- else:
- last = wiki
- if(wiki == 1):
- i[2] = 0
- i[3] = 0
- i[4] = 0
- i[5] = 0
- i[6] = 0
- elif(wiki == 2):
- i[3] = 0
- i[4] = 0
- i[5] = 0
- i[6] = 0
- elif(wiki == 3):
- i[4] = 0
- i[5] = 0
- i[6] = 0
- elif(wiki == 4):
- i[5] = 0
- i[6] = 0
- elif(wiki == 5):
- i[6] = 0
- if(wiki == 1):
- i[1] += 1
- elif(wiki == 2):
- i[2] += 1
- elif(wiki == 3):
- i[3] += 1
- elif(wiki == 4):
- i[4] += 1
- elif(wiki == 5):
- i[5] += 1
- else:
- i[6] += 1
- toc = str(i[1]) + '.' + str(i[2]) + '.' + str(i[3]) + '.' + str(i[4]) + '.' + str(i[5]) + '.' + str(i[6]) + '.'
- toc = re.sub("(?P<in>[0-9]0(?:[0]*)?)\.", '\g<in>#.', toc)
- toc = re.sub("0\.", '', toc)
- toc = re.sub("#\.", '.', toc)
- toc = re.sub("\.$", '', toc)
- test = re.search('([0-9]*)(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?(\.([0-9]*))?', toc)
- if(test):
- g = test.groups()
- if(g[4]):
- span = '<span id="out"></span>' * 4
- elif(g[3]):
- span = '<span id="out"></span>' * 3
- elif(g[2]):
- span = '<span id="out"></span>' * 2
- elif(g[1]):
- span = '<span id="out"></span>'
- else:
- span = ''
- rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + result[1] + '<br>'
- c = re.sub(" $", "", result[1])
- d = c
- c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
- data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<h' + str(wiki) + ' id="' + c + '"><a href="#toc" id="s-' + toc + '">' + toc + '.</a> ' + d + ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span></h' + str(wiki) + '>', data, 1);
- else:
- rtoc += '</div>'
-
- break
-
- data = re.sub("\[목차\]", rtoc, data)
-
- category = ''
- while(True):
- m = re.search("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", data)
- if(m):
- g = m.groups()
-
- if(not title == g[0]):
- cat_plus(title, g[0])
-
- if(category == ''):
- db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
- exists = db_get()
- if(exists):
- red = ""
- else:
- red = 'class="not_thing"'
-
- category += '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
- else:
- db_ex("select title from data where title = '" + db_pas(g[0]) + "'")
- exists = db_get()
- if(exists):
- red = ""
- else:
- red = 'class="not_thing"'
-
- category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g[0]) + '">' + re.sub("분류:", "", g[0]) + '</a>'
-
- data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
- else:
- break
- data = re.sub("'''(?P<in>.+?)'''(?!')", '<b>\g<in></b>', data)
- data = re.sub("''(?P<in>.+?)''(?!')", '<i>\g<in></i>', data)
- data = re.sub('~~(?P<in>.+?)~~(?!~)', '<s>\g<in></s>', data)
- data = re.sub('--(?P<in>.+?)--(?!-)', '<s>\g<in></s>', data)
- data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
- data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
- data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
-
- data = re.sub('<math>(?P<in>((?!<math>).)*)<\/math>', '$\g<in>$', data)
-
- data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
-
- data = re.sub('\[ruby\((?P<in>[^\,]*)\,\s?(?P<out>[^\)]*)\)\]', '<ruby>\g<in><rp>(</rp><rt>\g<out></rt><rp>)</rp></ruby>', data)
-
- data = re.sub("##\s?(?P<in>[^\n]*)\n", "<div style='display:none;'>\g<in></div>", data)
-
- while(True):
- m = re.search("\[\[파일:((?:(?!\]\]|\|).)*)(?:\|((?:(?!\]\]).)*))?\]\]", data)
- if(m):
- c = m.groups()
- if(c):
- if(not re.search("^파일:([^\n]*)", title)):
- backlink_plus(title, '파일:' + c[0], 'file')
- if(c[1]):
- n = re.search("width=([^ \n&]*)", c[1])
- e = re.search("height=([^ \n&]*)", c[1])
- if(n):
- a = n.groups()
- width = a[0]
- else:
- width = ''
- if(e):
- b = e.groups()
- height = b[0]
- else:
- height = ''
-
- try:
- extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
- img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
- data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", '<a href="/w/파일:' + extension[0] + img + '"><img src="/image/' + sha224(extension[0]) + img + '" width="' + width + '" height="' + height + '"></a>', data, 1)
- except:
- data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
- else:
- try:
- extension = re.search("^(.+)(\.(?:[Jj][Pp][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg]|[Pp][Nn][Gg]))$", c[0]).groups()
-
- img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", extension[1])
- data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", "<a href='/w/파일:" + extension[0] + img + "'><img src='/image/" + sha224(extension[0]) + img + "'></a>", data, 1)
- except:
- data = re.sub("\[\[파일:((?:(?!\]\]|\?).)*)(?:\?((?:(?!\]\]).)*))?\]\]", 'Error', data, 1)
- else:
- break
- else:
- break
-
- data = re.sub("\[br\]",'<br>', data)
-
- while(True):
- com = re.compile("\[youtube\((?:https:\/\/www\.youtube\.com\/watch\?v=|https:\/\/youtu\.be\/)?((?:(?!,|\)\]).)*)(?:,(?:\s)?)?(?:width=((?:(?!,|\)\]).)*))?(?:,(?:\s)?)?(?:height=((?:(?!,|\)\]).)*))?\)\]")
- m = com.search(data)
- if(m):
- result = m.groups()
- if(result[1]):
- if(result[2]):
- width = result[1]
- height = result[2]
- else:
- width = result[1]
- height = '315'
- elif(result[2]):
- height = result[2]
- width = '560'
- else:
- width = '560'
- height = '315'
- data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + result[0] + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
- else:
- break
-
- data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
-
- while(True):
- m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
- if(m):
- result = m.groups()
- rep = result[0]
- rep = re.sub("\\\#", "<sharp>", rep)
- a = re.search("^((?:(?!\|).)*)(?:\|(.*))?$", rep)
-
- results = a.groups()
-
- aa = re.search("^([^#]*)(#(?:.*))?$", results[0])
- if(results[1]):
- g = re.sub("<sharp>", "#", results[1])
- else:
- g = re.sub("<sharp>", "#", results[0])
-
- results = aa.groups()
-
- if(not results[1]):
- sharp = ''
- else:
- sharp = results[1]
-
- b = re.search("^http(?:s)?:\/\/", results[0])
- if(b):
- c = re.search("(?:\.[Jj][Pp][Gg]|\.[Pp][Nn][Gg]|\.[Gg][Ii][Ff]|\.[Jj][Pp][Ee][Gg])", results[0])
- if(c):
- img = results[0]
- img = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", img)
-
- data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + img + sharp + '">' + g + '</a>', data, 1)
- else:
- data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + sharp + '">' + g + '</a>', data, 1)
- else:
- if(results[0] == title):
- data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<b>' + g + '</b>', data, 1)
- else:
- db_ex("select title from data where title = '" + db_pas(results[0]) + "'")
- y = db_get()
- if(y):
- clas = ''
- else:
- clas = 'not_thing'
-
- nosharp = re.sub("<sharp>", "#", results[0])
- data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a title="' + re.sub('#', '\#', nosharp) + sharp + '" class="' + clas + '" href="/w/' + url_pas(nosharp) + sharp + '">' + g + '</a>', data, 1)
- backlink_plus(title, results[0], '')
- else:
- break
-
- while(True):
- 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|%)?))?)")
- m = com.search(data)
- if(m):
- result = m.groups()
- if(result[1]):
- if(result[2]):
- width = result[1]
- height = result[2]
- else:
- width = result[1]
- height = ''
- elif(result[2]):
- height = result[2]
- width = ''
- else:
- width = ''
- height = ''
- c = result[0]
- c = re.sub("\.(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])", "#\g<in>#", c)
- data = com.sub("<img width='" + width + "' height='" + height + "' src='" + c + "'>", data, 1)
- else:
- break
-
- while(True):
- m = re.search("((?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
- if(m):
- result = m.groups()
- end = str(result[0])
- while(True):
- isspace = re.search("( +)\*\s([^\n]*)", end)
- if(isspace):
- spacebar = isspace.groups()
- up = len(spacebar[0]) * 20
- end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
- else:
- break
- end = re.sub("\n", '', end)
- data = re.sub("(?:(?:(?:( +)\*\s([^\n]*))\n?)+)", '<ul id="list">' + end + '</ul>', data, 1)
- else:
- break
-
- now_time = get_time()
- data = re.sub('\[date\]', now_time, data)
-
- time_data = re.search('^([0-9]{4})-([0-9]{2})-([0-9]{2})', now_time)
- time = time_data.groups()
-
- age_data = re.findall('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', data)
- for age in age_data:
- year = int(time[0]) - int(age[0])
- if(age[1] > time[1]):
- year -= 1
- elif(age[1] == time[1]):
- if(age[2] > time[2]):
- year -= 1
-
- data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(year), data, 1)
-
- data = re.sub("#(?P<in>[Jj][Pp][Gg]|[Pp][Nn][Gg]|[Gg][Ii][Ff]|[Jj][Pp][Ee][Gg])#", ".\g<in>", data)
- data = re.sub("-{4,11}", "<hr>", data)
-
- while(True):
- b = re.search("(<\/h[0-9]>|\n)( +)", data)
- if(b):
- result = b.groups()
- up = re.sub(' ', '<span id="in"></span>', result[1])
- if(re.search('<\/h[0-9]>', result[0])):
- data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
- else:
- data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
- else:
- break
-
- a = 1
- tou = "<hr id='footnote'><div class='wiki-macro-footnote'><br>"
- namu = []
- while(True):
- b = re.search("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", data)
- if(b):
- results = b.groups()
- if(not results[1] and results[0]):
- i = 0
-
- while(True):
- try:
- if(namu[i] == results[0]):
- none_this = False
- break
- else:
- i += 2
- except:
- none_this = True
- break
-
- if(none_this == False):
- data = re.sub("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", "<sup><a class=\"footnotes\" title=\"" + namu[i + 1] + "\" id=\"rfn-" + str(a) + "\" href=\"#fn-" + str(a) + "\">[" + results[0] + "]</a></sup>", data, 1)
- else:
- data = re.sub("\[\*([^\s]*)(?:\s(((?!\]).)*))?\]", "<sup><a class=\"footnotes\" id=\"rfn-" + str(a) + "\" href=\"#fn-" + str(a) + "\">[" + results[0] + "]</a></sup>", data, 1)
- elif(results[0]):
- namu += [results[0]]
- namu += [results[1]]
-
- c = results[1]
- c = re.sub("<(?:[^>]*)>", '', c)
- tou += "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + results[0] + "]</a> " + results[1] + "</span><br>"
- 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)
- a += 1
- else:
- c = results[1]
- c = re.sub("<(?:[^>]*)>", '', c)
-
- tou += "<span class='footnote-list'><a href=\"#rfn-" + str(a) + "\" id=\"fn-" + str(a) + "\">[" + str(a) + "]</a> " + results[1] + "</span><br>"
- 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)
- else:
- tou += '</div>'
- if(tou == "<hr id='footnote'><div class='wiki-macro-footnote'><br></div>"):
- tou = ""
- break
-
- data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
- data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
- data = re.sub("\[각주\]", "<br>" + tou, data)
- data += tou
-
- if(category):
- data += '<div style="width:100%;border: 1px solid #777;padding: 5px;margin-top: 1em;">분류: ' + category + '</div>'
-
- data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
-
- while(True):
- y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
- if(y):
- a = y.groups()
-
- mid_data = re.sub("\|\|", "#table#", a[0])
- mid_data = re.sub("\r\n", "<br>", mid_data)
-
- data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
- else:
- break
-
- data = re.sub("#table#", "||", data)
- data = re.sub("<tablenobr>", "\r\n", data)
-
- while(True):
- m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
- if(m):
- results = m.groups()
- table = results[0]
- while(True):
- a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table)
- if(a):
- row = ''
- cel = ''
- celstyle = ''
- rowstyle = ''
- alltable = ''
- result = a.groups()
- if(result[1]):
- alltable = 'style="'
- celstyle = 'style="'
- rowstyle = 'style="'
- q = re.search("<table\s?width=((?:(?!>).)*)>", result[1])
- w = re.search("<table\s?height=((?:(?!>).)*)>", result[1])
- e = re.search("<table\s?align=((?:(?!>).)*)>", result[1])
- if(q):
- resultss = q.groups()
- alltable += 'width:' + resultss[0] + ';'
- if(w):
- resultss = w.groups()
- alltable += 'height:' + resultss[0] + ';'
- if(e):
- resultss = e.groups()
- if(resultss[0] == 'right'):
- alltable += 'margin-left:auto;'
- elif(resultss[0] == 'center'):
- alltable += 'margin:auto;'
- else:
- alltable += 'margin-right:auto;'
-
- ee = re.search("<table\s?textalign=((?:(?!>).)*)>", result[1])
- if(ee):
- resultss = ee.groups()
- if(resultss[0] == 'right'):
- alltable += 'text-align:right;'
- elif(resultss[0] == 'center'):
- alltable += 'text-align:center;'
- else:
- alltable += 'text-align:left;'
-
- r = re.search("<-((?:(?!>).)*)>", result[1])
- if(r):
- resultss = r.groups()
- cel = 'colspan="' + resultss[0] + '"'
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- t = re.search("<\|((?:(?!>).)*)>", result[1])
- if(t):
- resultss = t.groups()
- row = 'rowspan="' + resultss[0] + '"'
- ba = re.search("<rowbgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- bb = re.search("<rowbgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- bc = re.search("<rowbgcolor=(\w+)>", result[1])
- if(ba):
- resultss = ba.groups()
- rowstyle += 'background:' + resultss[0] + ';'
- elif(bb):
- resultss = bb.groups()
- rowstyle += 'background:' + resultss[0] + ';'
- elif(bc):
- resultss = bc.groups()
- rowstyle += 'background:' + resultss[0] + ';'
-
- z = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{6})>", result[1])
- x = re.search("<table\s?bordercolor=(#[0-9a-f-A-F]{3})>", result[1])
- c = re.search("<table\s?bordercolor=(\w+)>", result[1])
- if(z):
- resultss = z.groups()
- alltable += 'border:' + resultss[0] + ' 2px solid;'
- elif(x):
- resultss = x.groups()
- alltable += 'border:' + resultss[0] + ' 2px solid;'
- elif(c):
- resultss = c.groups()
- alltable += 'border:' + resultss[0] + ' 2px solid;'
-
- aq = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- aw = re.search("<table\s?bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- ae = re.search("<table\s?bgcolor=(\w+)>", result[1])
- if(aq):
- resultss = aq.groups()
- alltable += 'background:' + resultss[0] + ';'
- elif(aw):
- resultss = aw.groups()
- alltable += 'background:' + resultss[0] + ';'
- elif(ae):
- resultss = ae.groups()
- alltable += 'background:' + resultss[0] + ';'
-
- j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- l = re.search("<bgcolor=(\w+)>", result[1])
- if(j):
- resultss = j.groups()
- celstyle += 'background:' + resultss[0] + ';'
- elif(k):
- resultss = k.groups()
- celstyle += 'background:' + resultss[0] + ';'
- elif(l):
- resultss = l.groups()
- celstyle += 'background:' + resultss[0] + ';'
-
- aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1])
- ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1])
- ac = re.search("<(\w+)>", result[1])
- if(aa):
- resultss = aa.groups()
- celstyle += 'background:' + resultss[0] + ';'
- elif(ab):
- resultss = ab.groups()
- celstyle += 'background:' + resultss[0] + ';'
- elif(ac):
- resultss = ac.groups()
- celstyle += 'background:' + resultss[0] + ';'
-
- qa = re.search("<width=((?:(?!>).)*)>", result[1])
- qb = re.search("<height=((?:(?!>).)*)>", result[1])
- if(qa):
- resultss = qa.groups()
- celstyle += 'width:' + resultss[0] + ';'
- if(qb):
- resultss = qb.groups()
- celstyle += 'height:' + resultss[0] + ';'
-
- i = re.search("<\)>", result[1])
- o = re.search("<:>", result[1])
- p = re.search("<\(>", result[1])
- if(i):
- celstyle += 'text-align:right;'
- elif(o):
- celstyle += 'text-align:center;'
- elif(p):
- celstyle += 'text-align:left;'
-
- alltable += '"'
- celstyle += '"'
- rowstyle += '"'
-
- table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "<table " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "<table><tbody><tr><td " + cel + ">", table, 1)
- else:
- break
-
- table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
-
- while(True):
- b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table)
- if(b):
- row = ''
- cel = ''
- celstyle = ''
- rowstyle = ''
- result = b.groups()
- if(result[1]):
- celstyle = 'style="'
- rowstyle = 'style="'
-
- r = re.search("<-((?:(?!>).)*)>", result[1])
- if(r):
- resultss = r.groups()
- cel = 'colspan="' + resultss[0] + '"'
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- t = re.search("<\|((?:(?!>).)*)>", result[1])
- if(t):
- resultss = t.groups()
- row = 'rowspan="' + resultss[0] + '"'
-
- ba = re.search("<rowbgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- bb = re.search("<rowbgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- bc = re.search("<rowbgcolor=(\w+)>", result[1])
- if(ba):
- resultss = ba.groups()
- rowstyle = rowstyle + 'background:' + resultss[0] + ';'
- elif(bb):
- resultss = bb.groups()
- rowstyle = rowstyle + 'background:' + resultss[0] + ';'
- elif(bc):
- resultss = bc.groups()
- rowstyle = rowstyle + 'background:' + resultss[0] + ';'
-
- j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- l = re.search("<bgcolor=(\w+)>", result[1])
- if(j):
- resultss = j.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(k):
- resultss = k.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(l):
- resultss = l.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1])
- ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1])
- ac = re.search("<(\w+)>", result[1])
- if(aa):
- resultss = aa.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(ab):
- resultss = ab.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(ac):
- resultss = ac.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- qa = re.search("<width=((?:(?!>).)*)>", result[1])
- qb = re.search("<height=((?:(?!>).)*)>", result[1])
- if(qa):
- resultss = qa.groups()
- celstyle = celstyle + 'width:' + resultss[0] + ';'
- if(qb):
- resultss = qb.groups()
- celstyle = celstyle + 'height:' + resultss[0] + ';'
-
- i = re.search("<\)>", result[1])
- o = re.search("<:>", result[1])
- p = re.search("<\(>", result[1])
- if(i):
- celstyle = celstyle + 'text-align:right;'
- elif(o):
- celstyle = celstyle + 'text-align:center;'
- elif(p):
- celstyle = celstyle + 'text-align:left;'
- celstyle = celstyle + '"'
- rowstyle = rowstyle + '"'
-
- table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
- else:
- break
- while(True):
- c = re.search("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", table)
- if(c):
- row = ''
- cel = ''
- celstyle = ''
- result = c.groups()
- if(result[1]):
- celstyle = 'style="'
-
- r = re.search("<-((?:(?!>).)*)>", result[1])
- if(r):
- resultss = r.groups()
- cel = 'colspan="' + resultss[0] + '"';
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- t = re.search("<\|((?:(?!>).)*)>", result[1])
- if(t):
- resultss = t.groups()
- row = 'rowspan="' + resultss[0] + '"';
-
- j = re.search("<bgcolor=(#[0-9a-f-A-F]{6})>", result[1])
- k = re.search("<bgcolor=(#[0-9a-f-A-F]{3})>", result[1])
- l = re.search("<bgcolor=(\w+)>", result[1])
- if(j):
- resultss = j.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(k):
- resultss = k.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(l):
- resultss = l.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
-
- aa = re.search("<(#[0-9a-f-A-F]{6})>", result[1])
- ab = re.search("<(#[0-9a-f-A-F]{3})>", result[1])
- ac = re.search("<(\w+)>", result[1])
- if(aa):
- resultss = aa.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(ab):
- resultss = ab.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
- elif(ac):
- resultss = ac.groups()
- celstyle = celstyle + 'background:' + resultss[0] + ';'
-
- qa = re.search("<width=((?:(?!>).)*)>", result[1])
- qb = re.search("<height=((?:(?!>).)*)>", result[1])
- if(qa):
- resultss = qa.groups()
- celstyle = celstyle + 'width:' + resultss[0] + ';'
- if(qb):
- resultss = qb.groups()
- celstyle = celstyle + 'height:' + resultss[0] + ';'
-
- i = re.search("<\)>", result[1])
- o = re.search("<:>", result[1])
- p = re.search("<\(>", result[1])
- if(i):
- celstyle = celstyle + 'text-align:right;'
- elif(o):
- celstyle = celstyle + 'text-align:center;'
- elif(p):
- celstyle = celstyle + 'text-align:left;'
- celstyle = celstyle + '"'
-
- table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
- else:
- cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
- table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:<(?:(?:(?!>).)*)>)+)?", "</td><td " + cel + ">", table, 1)
- else:
- break
-
- data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
- else:
- break
-
- data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
- data = re.sub("<nowiki>(?P<in>.)<\/nowiki>", "\g<in>", data)
- data = re.sub("<space>", " ", data)
- data = re.sub('<\/blockquote>((\r)?\n){2}<blockquote>', '</blockquote><br><blockquote>', data)
- data = re.sub('\n', '<br>', data)
- data = re.sub('^<br>', '', data)
-
- return(data)
|