فهرست منبع

Merge pull request #409 from 2DU/master

Master
Surplus_Up (2DU) 8 سال پیش
والد
کامیت
22a650359c

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 258 - 118
app.py


+ 13 - 0
back_reset.py

@@ -1,28 +1,41 @@
+# 주요 모듈 불러옴
 import json
 import sqlite3
 import threading
+
+# 기타 코드 불러옴
 from func import *
 from mark import namumark
 
+# JSON 불러옴
 json_data = open('set.json').read()
 set_data = json.loads(json_data)
 
+# 디비 연결
 conn = sqlite3.connect(set_data['db'] + '.db', check_same_thread = False)
 curs = conn.cursor()
 
+# 파싱 해주는 함수
 def parser(data):
     namumark(conn, data[0], data[1], 1, 0, 0)
 
+# 역링크 전부 삭제
 curs.execute("delete from back")
 conn.commit()
 
+# 데이터에서 제목이랑 내용 불러옴
 curs.execute("select title, data from data")
 data = curs.fetchall()
 
+# for 돌려서 처리
 for test in data:
+    # 제목 프린트
     print(test[0])
+
+    # 스레드 기반으로 처리
     t = threading.Thread(target = parser, args = [test])
     t.start()
     t.join()
 
+# 커밋
 conn.commit()

+ 15 - 0
delete_recaptcha.py

@@ -0,0 +1,15 @@
+import json
+import sqlite3
+
+# JSON 연결
+json_data = open('set.json').read()
+set_data = json.loads(json_data)
+
+# 디비 연결
+conn = sqlite3.connect(set_data['db'] + '.db', check_same_thread = False)
+curs = conn.cursor()
+
+# 데이터 삭제
+curs.execute("delete from other where name = 'recaptcha'")
+curs.execute("delete from other where name = 'sec_re'")
+conn.commit()

+ 197 - 82
func.py

@@ -1,28 +1,31 @@
-from bottle import template, TEMPLATE_PATH, response
-
-from flask import session
+# 모듈들 불러옴
+from css_html_js_minify import html_minify, js_minify, css_minify
+from flask import session, render_template
+from urllib import parse
 
 import json
 import sqlite3
 import hashlib
-from urllib import parse
 import requests
 import re
 import html
-from css_html_js_minify import html_minify, js_minify, css_minify
 import time
 import os
 
-from set_mark.macro import get_time
-from set_mark.macro import ip_check
+# 일부 툴 불러옴
+from set_mark.tool import get_time
+from set_mark.tool import ip_check
+from set_mark.tool import url_pas
+from set_mark.tool import sha224
+
+# 나무마크 불러옴
 from mark import *
-from set_mark.link import url_pas
-from set_mark.link import sha224
 
 def captcha_get(conn):
     curs = conn.cursor()
 
     data = ''
+
     if custom(conn)[2] == 0:
         curs.execute('select data from other where name = "recaptcha"')
         recaptcha = curs.fetchall()
@@ -43,20 +46,23 @@ def captcha_post(test, conn, num = 1):
             sec_re = curs.fetchall()
             if sec_re and sec_re[0][0] != '':
                 data = requests.get('https://www.google.com/recaptcha/api/siteverify', params = { 'secret' : sec_re, 'response' : test })
-
                 if not data:
                     return 0
+
                 else:
                     json_data = data.json()
-
                     if data.status_code == 200 and json_data['success'] == True:
                         return 0
+
                     else:
                         return 1
+
             else:
                 return 0
+
         else:
             return 0
+
     else:
         pass
 
@@ -68,8 +74,10 @@ def ip_warring(conn):
         data = curs.fetchall()
         if data and data[0][0] != '':
             text_data = '<span>' + data[0][0] + '</span><hr>'
+
         else:
             text_data = '<span>비 로그인 상태입니다. 비 로그인으로 진행 시 아이피가 기록됩니다.</span><hr>'
+
     else:
         text_data = ''
 
@@ -77,25 +85,31 @@ def ip_warring(conn):
 
 def skin_check(conn):
     curs = conn.cursor()
+
     skin = './views/acme/'
+    
     try:
         curs.execute('select data from other where name = "skin"')
         skin_exist = curs.fetchall()
         if skin_exist:
-            if os.path.exists(os.path.abspath('./views/' + skin_exist[0][0] + '/index.tpl')) == 1:
+            if os.path.exists(os.path.abspath('./views/' + skin_exist[0][0] + '/index.html')) == 1:
                 skin = './views/' + skin_exist[0][0] + '/'
+
     except:
         pass
 
-    TEMPLATE_PATH.insert(0, skin)
+    return skin + 'index.html'
 
 def next_fix(link, num, page, end = 50):
     list_data = ''
+
     if num == 1:
         if len(page) == end:
             list_data += '<hr><a href="' + link + str(num + 1) + '">(이후)</a>'
+
     elif len(page) != end:
         list_data += '<hr><a href="' + link + str(num - 1) + '">(이전)</a>'
+
     else:
         list_data += '<hr><a href="' + link + str(num - 1) + '">(이전)</a> <a href="' + link + str(num + 1) + '">(이후)</a>'
 
@@ -106,6 +120,7 @@ def other2(origin):
 
 def wiki_set(conn, num):
     curs = conn.cursor()
+
     if num == 1:
         data_list = []
 
@@ -113,6 +128,7 @@ def wiki_set(conn, num):
         db_data = curs.fetchall()
         if db_data and db_data[0][0] != '':
             data_list += [db_data[0][0]]
+
         else:
             data_list += ['무명위키']
 
@@ -120,6 +136,7 @@ def wiki_set(conn, num):
         db_data = curs.fetchall()
         if db_data and db_data[0][0] != '':
             data_list += [db_data[0][0]]
+
         else:
             data_list += ['CC 0']
 
@@ -129,6 +146,7 @@ def wiki_set(conn, num):
         db_data = curs.fetchall()
         if db_data and db_data[0][0] != '':
             data_list += [db_data[0][0]]
+
         else:
             data_list += [data_list[0]]
             
@@ -136,6 +154,7 @@ def wiki_set(conn, num):
         db_data = curs.fetchall()
         if db_data and db_data[0][0] != '':
             data_list += [db_data[0][0]]
+
         else:
             data_list += ['']
 
@@ -143,26 +162,34 @@ def wiki_set(conn, num):
 
     if num == 2:
         var_data = '위키:대문'
+
         curs.execute('select data from other where name = "frontpage"')
+
     elif num == 3:
         var_data = '2'
+
         curs.execute('select data from other where name = "upload"')
     
     db_data = curs.fetchall()
     if db_data and db_data[0][0] != '':
         return db_data[0][0]
+
     else:
         return var_data
 
 def diff(seqm):
     output = []
+
     for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
         if opcode == 'equal':
             output += [seqm.a[a0:a1]]
+
         elif opcode == 'insert':
             output += ["<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>"]
+
         elif opcode == 'delete':
             output += ["<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>"]
+
         elif opcode == 'replace':
             output += ["<span style='background:#FDD;'>" + seqm.a[a0:a1] + "</span>"]
             output += ["<span style='background:#CFC;'>" + seqm.b[b0:b1] + "</span>"]
@@ -171,32 +198,41 @@ def diff(seqm):
            
 def admin_check(conn, num, what):
     ip = ip_check() 
+
     curs = conn.cursor()
+
     curs.execute("select acl from user where id = ?", [ip])
     user = curs.fetchall()
     if user:
         reset = 0
+
         while 1:
             if num == 1 and reset == 0:
                 check = 'ban'
+
             elif num == 2 and reset == 0:
                 check = 'mdel'
+
             elif num == 3 and reset == 0:
                 check = 'toron'
+
             elif num == 4 and reset == 0:
                 check = 'check'
+
             elif num == 5 and reset == 0:
                 check = 'acl'
+
             elif num == 6 and reset == 0:
                 check = 'hidel'
+
             elif num == 7 and reset == 0:
                 check = 'give'
+
             else:
                 check = 'owner'
 
             curs.execute('select name from alist where name = ? and acl = ?', [user[0][0], check])
-            acl_data = curs.fetchall()
-            if acl_data:
+            if curs.fetchall():
                 if what:
                     curs.execute("insert into re_admin (who, what, time) values (?, ?, ?)", [ip, what, get_time()])
                     conn.commit()
@@ -205,22 +241,28 @@ def admin_check(conn, num, what):
             else:
                 if reset == 0:
                     reset = 1
+
                 else:
                     break
 
 def ip_pas(conn, raw_ip):
     hide = 0
+
     curs = conn.cursor()
+
     if re.search("(\.|:)", raw_ip):
         if not re.search("^도구:", raw_ip):    
             curs.execute("select data from other where name = 'ip_view'")
-            d = curs.fetchall()
-            if d and d[0][0] != '':
+            data = curs.fetchall()
+            if data and data[0][0] != '':
                 ip = '<span style="font-size: 75%;">' + hashlib.md5(bytes(raw_ip, 'utf-8')).hexdigest() + '</span>'
+
                 if not admin_check(conn, 'ban', None):
                     hide = 1
+
             else:
                 ip = raw_ip
+
         else:
             ip = raw_ip
             hide = 1
@@ -228,8 +270,9 @@ def ip_pas(conn, raw_ip):
         curs.execute("select title from data where title = ?", ['사용자:' + raw_ip])
         if curs.fetchall():
             ip = '<a href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
+
         else:
-            ip = '<a class="not_thing" href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
+            ip = '<a id="not_thing" href="/w/' + url_pas('사용자:' + raw_ip) + '">' + raw_ip + '</a>'
          
     if hide == 0:
         ip += ' <a href="/record/' + url_pas(raw_ip) + '">(기록)</a>'
@@ -238,8 +281,10 @@ def ip_pas(conn, raw_ip):
 
 def custom(conn):
     curs = conn.cursor()
+
     if 'MyMaiToNight' in session:
         user_head = session['MyMaiToNight']
+
     else:
         user_head = ''
 
@@ -247,8 +292,10 @@ def custom(conn):
         curs.execute('select name from alarm where name = ? limit 1', [ip_check()])
         if curs.fetchall():
             user_icon = 2
+
         else:
             user_icon = 1
+
     else:
         user_icon = 0
 
@@ -257,16 +304,20 @@ def custom(conn):
         data = curs.fetchall()
         if data:
             email = data[0][0]
+
         else:
             email = ''
+
     else:
         email = ''
 
     return ['', '', user_icon, user_head, email]
 
 def acl_check(conn, name):
-    ip = ip_check()
     curs = conn.cursor()
+
+    ip = ip_check()
+
     if ban_check(conn) == 1:
         return 1
 
@@ -278,12 +329,12 @@ def acl_check(conn, name):
             return 0
 
         curs.execute("select dec from acl where title = ?", ['사용자:' + acl_n[0]])
-        acl_d = curs.fetchall()
-        if acl_d:
-            if acl_d[0][0] == 'all':
+        acl_data = curs.fetchall()
+        if acl_data:
+            if acl_data[0][0] == 'all':
                 return 0
 
-            if acl_d[0][0] == 'user' and not re.search("(\.|:)", ip):
+            if acl_data[0][0] == 'user' and not re.search("(\.|:)", ip):
                 return 0
 
             if ip != acl_n[0] or re.search("(\.|:)", ip):
@@ -291,6 +342,7 @@ def acl_check(conn, name):
         
         if ip == acl_n[0] and not re.search("(\.|:)", ip) and not re.search("(\.|:)", acl_n[0]):
             return 0
+
         else:
             return 1
 
@@ -299,31 +351,31 @@ def acl_check(conn, name):
         return 1
 
     curs.execute("select acl from user where id = ?", [ip])
-    user_d = curs.fetchall()
+    user_data = curs.fetchall()
 
     curs.execute("select dec from acl where title = ?", [name])
-    acl_d = curs.fetchall()
-    if acl_d:
-        if acl_d[0][0] == 'user':
-            if not user_d:
+    acl_data = curs.fetchall()
+    if acl_data:
+        if acl_data[0][0] == 'user':
+            if not user_data:
                 return 1
 
-        if acl_d[0][0] == 'admin':
-            if not user_d:
+        if acl_data[0][0] == 'admin':
+            if not user_data:
                 return 1
 
             if not admin_check(conn, 5, 'edit (' + name + ')') == 1:
                 return 1
 
     curs.execute('select data from other where name = "edit"')
-    set_d = curs.fetchall()
-    if set_d:
-        if set_d[0][0] == 'user':
-            if not user_d:
+    set_data = curs.fetchall()
+    if set_data:
+        if set_data[0][0] == 'user':
+            if not user_data:
                 return 1
 
-        if set_d[0][0] == 'admin':
-            if not user_d:
+        if set_data[0][0] == 'admin':
+            if not user_data:
                 return 1
 
             if not admin_check(conn, 5, None) == 1:
@@ -333,7 +385,9 @@ def acl_check(conn, name):
 
 def ban_check(conn):
     ip = ip_check()
+
     curs = conn.cursor()
+
     band = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
     if band:
         band_it = band.groups()
@@ -342,7 +396,7 @@ def ban_check(conn):
         
     curs.execute("select block from ban where block = ? and band = 'O'", [band_it[0]])
     band_d = curs.fetchall()
-
+    
     curs.execute("select block from ban where block = ?", [ip])
     ban_d = curs.fetchall()
     if band_d or ban_d:
@@ -352,175 +406,236 @@ def ban_check(conn):
         
 def topic_check(conn, name, sub):
     ip = ip_check()
+
     curs = conn.cursor()
+
     if ban_check(conn) == 1:
         return 1
 
     curs.execute("select title from stop where title = ? and sub = ?", [name, sub])
-    topic_s = curs.fetchall()
-    if topic_s:
+    if curs.fetchall():
         return 1
 
     return 0
 
+def ban_insert(conn, name, end, why, login, blocker):
+    curs = conn.cursor()
+
+    time = get_time()
+
+    if re.search("^([0-9]{1,3}\.[0-9]{1,3})$", name):
+        band = 'O'
+    else:
+        band = ''
+
+    curs.execute("select block from ban where block = ?", [name])
+    if curs.fetchall():
+        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)", [name, '해제', time, blocker, '', band])
+        curs.execute("delete from ban where block = ?", [name])
+
+    else:
+        if login:
+            login = 'O'
+            
+        else:
+            login = ''
+
+        if end != '':
+            end += ' 00:00:00'
+
+        print(end)
+
+        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)", [name, end, time, blocker, why, band])
+        curs.execute("insert into ban (block, end, why, band, login) values (?, ?, ?, ?, ?)", [name, end, why, band, login])
+    
+    conn.commit()
+
 def rd_plus(conn, title, sub, date):
     curs = conn.cursor()
+
     curs.execute("select title from rd where title = ? and sub = ?", [title, sub])
     if curs.fetchall():
         curs.execute("update rd set date = ? where title = ? and sub = ?", [date, title, sub])
+
     else:
         curs.execute("insert into rd (title, sub, date) values (?, ?, ?)", [title, sub, date])
 
 def history_plus(conn, title, data, date, ip, send, leng):
     curs = conn.cursor()
+
     curs.execute("select id from history where title = ? order by id + 0 desc limit 1", [title])
-    d = curs.fetchall()
-    if d:
-        curs.execute("insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, ?, ?)", [str(int(d[0][0]) + 1), title, data, date, ip, send, leng])
+    id_data = curs.fetchall()
+    if id_data:
+        curs.execute("insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, ?, ?)", [str(int(id_data[0][0]) + 1), title, data, date, ip, send, leng])
+        
     else:
         curs.execute("insert into history (id, title, data, date, ip, send, leng) values ('1', ?, ?, ?, ?, ?, ?)", [title, data, date, ip, send + ' (새 문서)', leng])
 
-def leng_check(a, b):
-    if a < b:
-        c = b - a
-        c = '+' + str(c)
-    elif b < a:
-        c = a - b
-        c = '-' + str(c)
+def leng_check(first, second):
+    if first < second:
+        all_plus = '+' + str(second - first)
+
+    elif second < first:
+        all_plus = '-' + str(first - second)
+
     else:
-        c = '0'
+        all_plus = '0'
         
-    return c
+    return all_plus
 
 def redirect(data):
     return '<meta http-equiv="refresh" content="0; url=' + data + '">'
 
 def re_error(conn, data):
     curs = conn.cursor()
+
     if data == '/ban':
         ip = ip_check()
-        end = '|| 사유 || 권한이 맞지 않는 상태 입니다. ||'
+
+        end = '<li>사유 : 권한이 맞지 않는 상태 입니다.</li>'
+
         if ban_check(conn) == 1:
             curs.execute("select end, why from ban where block = ?", [ip])
-            d = curs.fetchall()
-            if not d:
-                m = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
-                if m:
+            end_data = curs.fetchall()
+            if not end_data:
+                match = re.search("^([0-9]{1,3}\.[0-9]{1,3})", ip)
+                if match:
                     curs.execute("select end, why from ban where block = ? and band = 'O'", [m.groups()[0]])
-                    d = curs.fetchall()
+                    end_data = curs.fetchall()
             
-            if d:
-                end = '|| 상태 ||'
-                if d[0][0]:
-                    now = int(re.sub('(:|-| )', '', get_time()))
-                    day = re.sub('\-', '', d[0][0])              
-                              
-                    if re.search(':', day):
-                        day = re.sub('( |:)', '', day)
-                    else:
-                        day += '000000'
+            if end_data:
+                end = '<li>상태 : '
+
+                if end_data[0][0]:
+                    now = int(re.sub('(\-| |:)', '', get_time()))
+                    day = int(re.sub('(\-| |:)', '', end_data[0][0]))
                     
-                    if now >= int(day):
+                    if now >= day:
                         curs.execute("delete from ban where block = ?", [ip])
                         conn.commit()
-                        
-                        end += '차단이 풀렸습니다. 다시 시도  보세요.'
+
+                        end += '차단이 풀렸습니다. 다시 해보세요.'
                     else:
-                        end += d[0][0] + ' 까지 차단 상태 입니다.'
+                        end += '차단 중 : ' + end_data[0][0]
+
                 else:
-                    end += '영구 차단 상태 입니다.'
+                    end += '무기한 차단 상태 입니다.'
                 
-                end += '||'
+                end += '</li>'
 
-                if d[0][1] != '':
-                    end += '\r\n|| 사유 || ' + d[0][1] + ' ||'
+                if end_data[0][1] != '':
+                    end += '<li>사유 : ' + end_data[0][1] + '</li>'
 
-        return html_minify(template('index', 
+        return html_minify(render_template(skin_check(conn), 
             imp = ['권한 오류', wiki_set(conn, 1), custom(conn), other2([0, 0])],
-            data = namumark(conn, "", "[목차(없음)]\r\n== 권한 상태 ==\r\n" + end, 0, 0, 0),
+            data = '<h2>권한 상태</h2><ul>' + end + '</ul>',
             menu = 0
         ))
 
-    d = re.search('\/error\/([0-9]+)', data)
-    if d:
-        num = int(d.groups()[0])
+    error_data = re.search('\/error\/([0-9]+)', data)
+    if error_data:
+        num = int(error_data.groups()[0])
         if num == 1:
             title = '권한 오류'
             data = '비 로그인 상태 입니다.'
+
         elif num == 2:
             title = '권한 오류'
             data = '이 계정이 없습니다.'
+
         elif num == 3:
             title = '권한 오류'
             data = '권한이 모자랍니다.'
+
         elif num == 4:
             title = '권한 오류'
             data = '관리자는 차단, 검사 할 수 없습니다.'
+
         elif num == 5:
             title = '사용자 오류'
             data = '그런 계정이 없습니다.'
+
         elif num == 6:
             title = '가입 오류'
             data = '동일한 아이디의 사용자가 있습니다.'
+
         elif num == 7:
             title = '가입 오류'
             data = '아이디는 20글자보다 짧아야 합니다.'
+
         elif num == 8:
             title = '가입 오류'
             data = '아이디에는 한글과 알파벳과 공백만 허용 됩니다.'
+
         elif num == 9:
             title = '파일 올리기 오류'
             data = '파일이 없습니다.'
+
         elif num == 10:
             title = '변경 오류'
             data = '비밀번호가 다릅니다.'
+
         elif num == 11:
             title = '로그인 오류'
             data = '이미 로그인 되어 있습니다.'
+
         elif num == 12:
             title = '편집 오류'
             data = '누군가 먼저 편집 했습니다.'
+
         elif num == 13:
             title = '리캡차 오류'
             data = '리캡차를 통과하세요.'
+
         elif num == 14:
             title = '파일 올리기 오류'
             data = 'jpg, gif, jpeg, png, webp만 가능 합니다.'
+
         elif num == 15:
             title = '편집 오류'
             data = '편집 기록은 500자를 넘을 수 없습니다.'
+
         elif num == 16:
             title = '파일 올리기 오류'
             data = '동일한 이름의 파일이 있습니다.'
+
         elif num == 17:
             title = '파일 올리기 오류'
             data = '파일 용량은 ' + wiki_set(conn, 3) + 'MB를 넘길 수 없습니다.'
+
         elif num == 18:
             title = '편집 오류'
             data = '내용이 원래 문서와 동일 합니다.'
+
         elif num == 19:
             title = '이동 오류'
             data = '이동 하려는 곳에 문서가 이미 있습니다.'
+
         elif num == 20:
             title = '비밀번호 오류'
             data = '재 확인이랑 비밀번호가 다릅니다.'
+
         elif num == 21:
             title = '편집 오류'
             data = '편집 필터에 의해 검열 되었습니다.'
+
         elif num == 22:
             title = '파일 올리기 오류'
             data = '파일 이름은 알파벳, 한글, 띄어쓰기, 언더바, 빼기표만 허용 됩니다.'
+
         else:
             title = '정체 불명의 오류'
             data = '???'
 
         if title:
-            return html_minify(template('index', 
+            return html_minify(render_template(skin_check(conn), 
                 imp = [title, wiki_set(conn, 1), custom(conn), other2([0, 0])],
-                data = namumark(conn, "", "[목차(없음)]\r\n== 오류 발생 ==\r\n" + data, 0, 0, 0),
+                data = '<h2>오류 발생</h2><ul><li>' + data + '</li></ul>',
                 menu = 0
             ))
+
         else:
             return redirect('/')
+
     else:
         return redirect('/')

+ 16 - 71
mark.py

@@ -1,17 +1,4 @@
 from set_mark.start import start
-from set_mark.mid_pas import mid_pas
-from set_mark.html_pas import html_pas
-from set_mark.include_pas import include_pas
-from set_mark.macro import macro
-from set_mark.redirect_pas import redirect_pas
-from set_mark.blockquote import blockquote
-from set_mark.toc_pas import toc_pas
-from set_mark.text_help import text_help
-from set_mark.link import link
-from set_mark.indent import indent
-from set_mark.footnote import footnote
-from set_mark.table import table
-from set_mark.end import end
 
 import re
 import html
@@ -20,72 +7,30 @@ from urllib import parse
 import time
 import threading
 
-def send_p(d):
-    d = html.escape(d)
-
-    js_p = re.compile('javascript:', re.I)
-    d = js_p.sub('', d)
-
-    d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)  
-
-    return d
-
-def url_pas(data):
-    return parse.quote(data).replace('/','%2F')
+def send_parser(data):
+    data = html.escape(data)
+    
+    javascript = re.compile('javascript:', re.I)
+    
+    data = javascript.sub('', data)
+    data = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + parse.quote('\g<in>').replace('/','%2F') + '">\g<in></a>', data)  
+    
+    return data
     
 def plusing(conn, name, link, backtype):
     curs = conn.cursor()
-
     curs.execute("select title from back where title = ? and link = ? and type = ?", [link, name, backtype])
     if not curs.fetchall():
         curs.execute("insert into back (title, link, type) values (?, ?, ?)", [link, name, backtype])
 
-def namumark(conn, title, data, num, in_c, toc_y):  
-    data = start(data)
-    data = html_pas(data)
-    
-    fol_num = 0
-    a = mid_pas(data, fol_num, 0, in_c, toc_y)
-    data = a[0]
-    fol_num = a[1]
-
-    a = include_pas(conn, data, title, in_c, num, toc_y, fol_num)
-    data = a[0]
-    category = a[1]
-    fol_num = a[2]
-    backlink = a[3]
-    
-    data = re.sub("\n##\s?([^\n]*)", "", data)    
-    a = redirect_pas(data, title, backlink)
-    data = a[0]
-    backlink = a[1]
-    
-    data = blockquote(data)
-    data = toc_pas(data, title, num, toc_y)
-    data = text_help(data)
-    data = macro(data)
-    
-    a = link(conn, title, data, num, category, backlink)
-    data = a[0]
-    category = a[1]
-    backlink = a[2]
-    
-    data = indent(data)
-    data = footnote(data, fol_num)
-    data = table(data)
-    data = end(data, category)
-
-    data += '<script>function folding(num, test = 0) { var fol = document.getElementById(\'folding_\' + num); \
-            if(fol.style.display == \'inline-block\' || fol.style.display == \'block\') { fol.style.display = \'none\'; } \
-            else { if(num % 3 == 0 && test != 1) { fol.style.display = \'block\'; } else { fol.style.display = \'inline-block\'; } } } \
-            </script>'
-    
+def namumark(conn, title, data, num):
+    data = start(conn, data, title)
     if num == 1:        
-        for d4 in backlink:
-            t = threading.Thread(target = plusing, args = [conn, d4[0], d4[1], d4[2]])
-            t.start()
-            t.join()
+        for back_data in data[2]:
+            thread_start = threading.Thread(target = plusing, args = [conn, back_data[0], back_data[1], back_data[2]])
+            thread_start.start()
+            thread_start.join()
 
         conn.commit()
         
-    return data
+    return data[0] + data[1]

+ 2 - 1
requirements.txt

@@ -4,4 +4,5 @@ tornado >= 4.5.2
 bcrypt >= 3.1.3
 requests >= 2.13.0
 flask >= 0.12.2
-flask-Reggie >= 0.0.2
+flask-Reggie >= 0.0.2
+flask-compress >= 1.4.0

+ 0 - 14
set_mark/blockquote.py

@@ -1,14 +0,0 @@
-import re
-
-def blockquote(data):
-    while 1:
-        m = re.search("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", data)
-        if m:
-            result = m.groups()
-            blockquote = result[0]
-            blockquote = re.sub("\n&gt;\s?", "\n", blockquote)
-            data = re.sub("\n&gt;\s?((?:[^\n]*)(?:(?:(?:(?:\n&gt;\s?)(?:[^\n]*))+)?))", "\n<blockquote>" + blockquote + "</blockquote>", data, 1)
-        else:
-            break
-
-    return data

+ 0 - 22
set_mark/end.py

@@ -1,22 +0,0 @@
-import re
-
-def end(data, category):    
-    if category:
-        data += '<div style="margin-top: 30px;" id="cate">분류: ' + category + '</div>'
-            
-    data = re.sub("\r\n(?P<in><h[0-6])", "\g<in>", data)
-    data = re.sub("(\n<nobr>|<nobr>\n|<nobr>)", "", data)
-    data = re.sub("#no#(?P<in>.)#\/no#", "\g<in>", data)
-    data = re.sub("&lt;space&gt;", " ", data)
-
-    data = re.sub('<\/blockquote>(?:(?:\r)?\n){2}<blockquote>', '</blockquote><blockquote>', data)
-    data = re.sub('<\/blockquote>(?:(?:\r)?\n)<br><blockquote>', '</blockquote><blockquote>', data)
-
-    data = re.sub('\n', '<br>', data)
-    data = re.sub('<hr id="under_bar"([^>]*)><br>', '<hr id="under_bar" style="margin-top: -5px;">', data)
-    data = re.sub('&lt;isbr&gt;', '\r\n', data)
-    data = re.sub('^(?:<br>|\r|\n| )+', '', data)
-    data = re.sub('^<div style="margin-top: 30px;" id="cate">', '<div id="cate">', data)        
-    data = re.sub('&amp;#92;', '&#92;', data)
-
-    return data

+ 0 - 77
set_mark/footnote.py

@@ -1,77 +0,0 @@
-import re
-
-def footnote(data, fol_num):
-    a = 1
-    tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
-    namu = []
-    div = ''
-    pop_re = re.compile('(?:\[\*([^\s]*)(?:\s((?:(?!\[|\]).)*))?\]|(\[각주\]))')
-    while 1:
-        b = pop_re.search(data)
-        if b:
-            results = b.groups()
-            try:
-                if not results[1] and results[0]:
-                    i = 0
-                    
-                    while 1:
-                        try:
-                            if namu[i] == results[0]:
-                                none_this = 0
-                                break
-                            else:
-                                i += 2
-                        except:
-                            none_this = 1
-                            break
-                            
-                    if none_this == 0:
-                        data = pop_re.sub("<sup><a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ", 1);' id='rfn-" + str(a) + "'>(" + results[0] + ")</a></sup>", data, 1)
-                        div += "<div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'><a onclick='folding(" + str(fol_num) + ");'" + \
-                                " href='#fn-" + str(a) + "'>(" + results[0] + ")</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>(X)</a> " + \
-                                namu[i + 1] + "</div>"
-                    else:
-                        data = pop_re.sub("<sup><a href='javascript:void(0);' id='rfn-" + str(a) + "'>(" + results[0] + ")</a></sup>", data, 1)
-                else:
-                    if(results[0]):                
-                        namu += [results[0]]
-                        namu += [results[1]]
-
-                        data = pop_re.sub("<sup><a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ", 1);' id='rfn-" + str(a) + "'>(" + results[0] + ")</a></sup>", data, 1)
-
-                        tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>(" + results[0] + ")</a> " + results[1] + "</span><br>"                        
-                        div += "<div class='popup' style='display: none;' id='folding_" + str(fol_num) + "'><a onclick='folding(" + str(fol_num) + ");'" + \
-                                " href='#fn-" + str(a) + "'>(" + results[0] + ")</a> <a href='javascript:void(0);' onclick='folding(" + str(fol_num) + ");'>" + \
-                                "(X)</a> " + results[1] + "</div>"
-
-                    else:                    
-                        data = pop_re.sub('<sup><a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ', 1);" id="rfn-' + str(a) + '">(' + str(a) + ')</a></sup>', data, 1)
-
-                        tou += "<span id='footnote-list'><a href='#rfn-" + str(a) + "' id='fn-" + str(a) + "'>(" + str(a) + ")</a> " + results[1] + "</span><br>"
-                        div += '<div class="popup" style="display: none;" id="folding_' + str(fol_num) + '"><a onclick="folding(' + str(fol_num) + ');"' + \
-                                ' href="#fn-' + str(a) + '">(' + str(a) + ')</a> <a href="javascript:void(0);" onclick="folding(' + str(fol_num) + ');">(X)</a> ' + \
-                                results[1] + '</div>'
-                    a += 1
-
-                fol_num += 2
-            except:
-                tou += '</div>'
-
-                if tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>":
-                    tou = ""
-
-                data = pop_re.sub("<br>" + tou, data, 1)
-                tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
-        else:
-            tou += '</div>'
-
-            if tou == "<hr style='margin-top: 30px;' id='footnote'><div><br></div>":
-                tou = ""
-
-            break
-    
-    data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
-    data = re.sub("(?:(?:<br>| |\r|\n)+)$", "", data)
-    data += tou + div
-    
-    return data

+ 0 - 38
set_mark/html_pas.py

@@ -1,38 +0,0 @@
-import re
-import html
-
-def html_pas(data):
-    data = re.sub('%H%', '<', data)
-    data = re.sub('%\/H%', '>', data)
-
-    d_list = re.findall('<(\/)?([^> ]+)( (?:[^>]+)?)?>', data)
-    for i_list in d_list:
-        if i_list[0] == '':
-            if i_list[1] in ['div', 'span', 'embed', 'iframe', 'ruby', 'rp', 'rt']:
-                if re.search('<\/' + i_list[1] + '>', data):
-                    src = re.search('src=([^ ]*)', i_list[2])
-                    if src:
-                        v_src = re.search('http(?:s)?:\/\/([^/\'" ]*)', src.groups()[0])
-                        data_list = ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com", "serviceapi.rmcnmv.naver.com"]
-                        if v_src:
-                            if not v_src.groups()[0] in data_list:
-                                ot = re.sub('src=([^ ]*)', '', i_list[2])
-                            else:
-                                ot = i_list[2]
-                        else:
-                            ot = re.sub('src=([^ ]*)', '', i_list[2])
-                    else:
-                        ot = i_list[2]
-
-                    po = re.compile('position', re.I)
-                    data = data.replace('<' + i_list[1] + i_list[2] + '>', '%H%' + i_list[1] + po.sub('', ot) + '%/H%', 1)
-                    data = re.sub('<\/' + i_list[1] + '>', '%H%/' + i_list[1] + '%/H%', data, 1)
-
-    data = html.escape(data)
-    data = data.replace('\\', '&#92;')
-    
-    end = re.findall('%H%((?:(?!%/H%).)*)%/H%', data)
-    for d_end in end:
-        data = re.sub('%H%((?:(?!%/H%).)*)%/H%', '<' + re.sub('&quot;', '"', re.sub('&#x27;', "'", d_end)) + '>', data, 1)
-
-    return data

+ 0 - 70
set_mark/include_pas.py

@@ -1,70 +0,0 @@
-from . import html_pas
-from . import link
-from . import mid_pas
-from . import toc_pas
-import sqlite3
-from urllib import parse
-import re
-
-def url_pas(data):
-    return parse.quote(data).replace('/','%2F')
-    
-def include_pas(conn, data, title, in_c, num, toc_y, fol_num):
-    curs = conn.cursor()
-
-    category = ''
-    backlink = []
-    data = data.replace('&#92;&#92;,', '#comma#')
-    
-    include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]((?:(?!\n))*)")
-    m = include.findall(data)
-    for results in m:
-        if results[0] == title:
-            data = include.sub("<b>" + results[0] + "</b>", data, 1)
-        else:
-            backlink += [[title, results[0], 'include']]
-
-            curs.execute("select data from data where title = ?", [results[0]])
-            in_con = curs.fetchall()
-            if(in_con):                        
-                in_data = in_con[0][0]
-                in_data = include.sub("", in_data)
-                in_data = re.sub("\[\[(분류:(?:(?:(?!\]\]|#include).)+))\]\]", "", in_data)
-                in_data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", in_data))
-                in_data = html_pas.html_pas(in_data)
-                
-                var_d = mid_pas.mid_pas(in_data, fol_num, 1, in_c, toc_y)
-                var_d2 = link.link(conn, title, var_d[0], 0, category, backlink)
-
-                in_data = var_d2[0]
-                category = var_d2[1]
-                fol_num = var_d[1]
-                
-                if results[1]:
-                    a = results[1]
-                    while 1:
-                        g = re.search("([^= ,]*)\=([^,]*)", a)
-                        if g:
-                            result = g.groups()
-                            in_data = re.sub("@" + result[0] + "@", result[1].replace('#comma#', ','), in_data)
-                            a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
-                        else:
-                            break       
-
-                in_data = toc_pas.toc_pas(in_data, results[0], num, toc_y)
-                            
-                if results[2]:
-                    test = '<br>'
-                else:
-                    if re.search('\|\|', in_data):
-                        test = '\n'
-                    else:
-                        test = ''
-
-                data = include.sub('<nobr><a id="include_link" href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><br><span>' + in_data + '</span>' + test, data, 1)
-            else:
-                data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
-
-    data = data.replace('#comma#', '&#92;&#92;,')
-
-    return [data, category, fol_num, backlink]

+ 0 - 41
set_mark/indent.py

@@ -1,41 +0,0 @@
-import re
-
-def indent(data):
-    while 1:
-        m = re.search("(\n(?:(?:( *)\* (?:[^\n]*))\n?)+)", data)
-        if m:
-            result = m.groups()
-            end = str(result[0])
-
-            while 1:
-                isspace = re.search("\n( *)\* ([^\n]*)", end)
-                if isspace:
-                    spacebar = isspace.groups()
-                    if len(spacebar[0]) == 0:
-                        up = 20
-                    else:
-                        up = len(spacebar[0]) * 20
-
-                    end = re.sub("\n( *)\* ([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
-                else:
-                    break
-
-            end = re.sub("\n", '', end)
-            data = re.sub("(\n(?:(?:( *)\* (?:[^\n]*))\n?)+)", '<ul style="margin-top: 10px; margin-bottom: 10px;" id="list">' + end + '</ul>', data, 1)
-        else:
-            break
-
-    while 1:
-        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
-            
-    return data

+ 0 - 179
set_mark/link.py

@@ -1,179 +0,0 @@
-import sqlite3
-import re
-from urllib import parse
-import hashlib
-
-def url_pas(data):
-    return parse.quote(data).replace('/','%2F')
-
-def sha224(data):
-    return hashlib.sha224(bytes(data, 'utf-8')).hexdigest()
-
-def link(conn, title, data, num, category, backlink):
-    curs = conn.cursor()
-    data = data.replace('&#92;', '\\')
-    
-    m = re.findall("\[\[(분류:(?:(?:(?!\]\]|#).)+))((?:#(?:(?:(?!#|\]\]).)+))+)?\]\]", data)
-    for g in m:
-        if title != g[0]:
-            if num == 1:
-                backlink += [[title, g[0], 'cat']]
-                
-            curs.execute("select title from data where title = ?", [g[0]])
-            if curs.fetchall():
-                red = ""
-            else:
-                red = 'class="not_thing"'
-
-            if(category != ''):    
-                category += ' / '                
-
-            style = ''
-            title_name = re.sub("분류:", "", g[0])
-            if g[1]:
-                if re.search('#blur', g[1]):
-                    style = ' onmouseover="this.innerHTML=\'' + title_name + '\';"'
-                    title_name = '<span id="inside">스포일러</span>'
-                
-            category += '<a ' + red + ' ' + style + ' href="/w/' + url_pas(g[0]) + '">' + title_name + '</a>'
-        
-        data = re.sub("\[\[(분류:(?:(?:(?!\]\]|#).)+))((?:#(?:(?:(?!#|\]\]).)+))+)?\]\]", '', data, 1)
-    
-    test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
-    for wiki in test:
-        if wiki[1]:
-            out = wiki[1]
-        else:
-            out = wiki[0]
-
-        data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + out + '</a>', data, 1)
-
-    test = re.findall('\[\[inter:([^:]+):((?:(?!\||]]).)+)(?:\|([^\]]+))?]]', data)
-    for wiki in test:
-        curs.execute('select link from inter where title = ?', [wiki[0]])
-        inter = curs.fetchall()
-        if not inter:
-            data = re.sub('\[\[inter:([^:]+):((?:(?!\||]]).)+)(?:\|([^\]]+))?]]', '인터위키 정보 없음', data, 1)
-        else:
-            if wiki[2]:
-                out = wiki[0] + ':' +  wiki[2]
-            else:
-                out = wiki[0] + ':' + wiki[1]
-
-            data = re.sub('\[\[inter:([^:]+):((?:(?!\||]]).)+)(?:\|([^\]]+))?]]', '<a id="inside" href="' + inter[0][0] + wiki[1] + '">' + out + '</a>', data, 1)
-     
-    data = re.sub("\[\[(?::(?P<in>(?:분류|파일):(?:(?:(?!\]\]).)*)))\]\]", "[[\g<in>]]", data)
-
-    a = re.findall('\[\[\.\.\/(\|(?:(?!]]).)+)?]]', data)
-    for i in a:
-        b = re.search('(.*)\/', title)
-        if b:
-            m = b.groups()
-            if i:
-                data = re.sub('\[\[\.\.\/(\|((?!]]).)+)?]]', '[[' + m[0] + i + ']]', data, 1)
-            else:
-                data = re.sub('\[\[\.\.\/(\|((?!]]).)+)?]]', '[[' + m[0] + ']]', data, 1)
-        else:
-            if i:
-                data = re.sub('\[\[\.\.\/(\|((?!]]).)+)?]]', '[[' + title + i + ']]', data, 1)
-            else:
-                data = re.sub('\[\[\.\.\/(\|((?!]]).)+)?]]', '[[' + title + ']]', data, 1)
-
-    data = re.sub('\[\[(?P<in>\/(?:(?!]]|\|).)+)(?P<out>\|(?:(?:(?!]]).)+))?]]', '[[' + title + '\g<in>\g<out>]]', data)
-                
-    link = re.compile('\[\[((?:(?!\[\[|\]\]|\|).)*)(?:\|((?:(?!\[\[|\]\]).)*))?\]\]')
-    while 1:
-        l_d = link.search(data)
-        if l_d:
-            d = l_d.groups()
-            if re.search('^(?:파일|외부):', d[0]):
-                width = ''
-                height = ''
-                align = ''
-                span = ['', '']
-                
-                try:        
-                    w_d = re.search('width=([0-9]+(?:[a-z%]+)?)', d[1])
-                    if w_d:
-                        width = 'width="' + w_d.groups()[0] + '" '
-                    
-                    h_d = re.search('height=([0-9]+(?:[a-z%]+)?)', d[1])
-                    if h_d:
-                        height = 'height="' + h_d.groups()[0] + '" '
-                        
-                    a_d = re.search('align=(center|right)', d[1])
-                    if a_d:
-                        span[0] = '<span style="display: block; text-align: ' + a_d.groups()[0] + ';">'
-                        span[1] = '</span>'
-                except:
-                    pass
-                    
-                f_d = re.search('^파일:([^.]+)\.(.+)$', d[0])
-                if f_d:
-                    if not re.search("^파일:([^\n]*)", title):
-                        if num == 1:
-                            backlink += [[title, d[0], 'file']]
-
-                    file_name = f_d.groups()
-
-                    curs.execute("select title from data where title = ?", ['파일:' + file_name[0] + '.' + file_name[1]])
-                    if not curs.fetchall():
-                        img = '<a class="not_thing" href="/w/' + url_pas('파일:' + file_name[0] + '.' + file_name[1]) + '">파일:' + file_name[0] + '.' + file_name[1] + '</a>'
-                    else:
-                        img = span[0] + '<img src="/image/' + sha224(file_name[0]) + '.' + file_name[1] + '" ' + width + height + '>' + span[1]
-                    
-                    data = link.sub(img, data, 1)
-                else:
-                    img = span[0] + '<img src="' + re.sub('^외부:', '', d[0]) + '" ' + width + height + '>' + span[1]
-                    data = link.sub(img, data, 1)
-            elif re.search('^https?:\/\/', re.sub('<([^>]*)>', '', d[0])):
-                view = d[0]
-                try:
-                    if re.search('(.+)', d[1]):
-                        view = d[1]
-                except:
-                    pass
-                
-                data = link.sub('<a class="out_link" rel="nofollow" href="' + re.sub('<([^>]*)>', '', d[0]) + '">' + view + '</a>', data, 1)
-            else:
-                view = d[0].replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
-                try:
-                    if re.search('(.+)', d[1]):
-                        view = d[1].replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
-                except:
-                    pass        
-                    
-                sh = ''
-                s_d = re.search('#((?:(?!x27;|#).)+)$', d[0])
-                if s_d:
-                    href = re.sub('#((?:(?!x27;|#).)+)$', '', d[0])
-                    sh = '#' + s_d.groups()[0]
-                else:
-                    href = d[0]
-                    
-                if d[0] == title:
-                    data = link.sub('<b>' + view + '</b>', data, 1)
-                elif re.search('^#', d[0]):
-                    data = link.sub('<a title="' + sh + '" href="' + sh + '">' + view + '</a>', data, 1)
-                else:                    
-                    a = re.sub('<([^>]*)>', '', href.replace('&#x27;', "'").replace('&quot;', '"').replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\'))
-                    
-                    if num == 1:
-                        backlink += [[title, a, '']]
-                    
-                    curs.execute("select title from data where title = ?", [a])
-                    if not curs.fetchall():
-                        no = 'class="not_thing"'
-                        
-                        if num == 1:
-                            backlink += [[title, a, 'no']]
-                    else:
-                        no = ''
-                    
-                    data = link.sub('<a ' + no + ' title="' + re.sub('<([^>]*)>', '', href) + sh + '" href="/w/' + url_pas(a) + sh + '">' + view.replace('\\', '\\\\') + '</a>', data, 1)
-        else:
-            break
-            
-    data = data.replace('\\', '&#92;')
-
-    return [data, category, backlink]

+ 0 - 114
set_mark/macro.py

@@ -1,114 +0,0 @@
-from flask import session, request
-
-from urllib import parse
-import time
-import datetime
-import re
-import json
-
-def get_time():
-    now = time.localtime()
-    date = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
-
-    return date
-    
-def ip_check():
-    if session and ('Now' and 'DREAMER') in session and session['Now'] == 1:
-        ip = session['DREAMER']
-    else:
-        try:
-            ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
-        except:
-            ip = 'None'
-
-    return str(ip)
-
-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 macro(data):      
-    data = savemark(data)
-    data = re.sub("\[anchor\((?P<in>[^\[\]]*)\)\]", '<span id="\g<in>"></span>', data)          
-    data = re.sub("\[nicovideo\((?P<in>[^,)]*)(?:(?:,(?:[^,)]*))+)?\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>]]", 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("\[br\]", '<br>', data)
-    
-    while 1:
-        com = re.compile("\[(youtube|kakaotv)\(([^, )]*)(,[^)]*)?\)\]")
-        m = com.search(data)
-        if m:
-            src = ''
-            width = '560'
-            height = '315'
-            time = '0'
-            
-            result = m.groups()
-            if result[1]:
-                yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[1])
-                if yudt:
-                    if yudt.groups()[0]:
-                        src = yudt.groups()[0]
-                    elif yudt.groups()[1]:
-                        src = yudt.groups()[1]
-                    elif yudt.groups()[2]:
-                        src = yudt.groups()[2]
-                else:
-                    src = ''
-                    
-            if result[2]:
-                mdata = re.search('width=([0-9%]*)', result[2])
-                if mdata:
-                    width = mdata.groups()[0]
-                
-                mdata = re.search('height=([0-9%]*)', result[2])
-                if mdata:
-                    height = mdata.groups()[0]
-                    
-                mdata = re.search('start=([0-9]*)', result[2])
-                if mdata:
-                    time = mdata.groups()[0]
-
-            if result[0] == 'youtube':
-                data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + src + '?start=' + time + '" frameborder="0" allowfullscreen></iframe><br>', data, 1)
-            else:
-                data = com.sub('<iframe width="' + width + '" height="' + height + '" src="https://tv.kakao.com/embed/player/cliplink/' + src + '?service=kakao_tv&start=' + time + '" allowfullscreen frameborder="0" scrolling="no"></iframe><br>', 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:
-        old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
-        will = datetime.datetime.strptime(age, '%Y-%m-%d')
-        e_data = old - will
-
-        data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(int(int(e_data.days) / 365)), data, 1)
-
-    dday_data = re.findall('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
-    for dday in dday_data:
-        old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
-        will = datetime.datetime.strptime(dday, '%Y-%m-%d')
-        e_data = old - will
-
-        if re.search('^-', str(e_data.days)):
-            e_day = str(e_data.days)
-        else:
-            e_day = '+' + str(e_data.days)
-
-        data = re.sub('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', e_day, data, 1)
-        
-    return data

+ 0 - 142
set_mark/mid_pas.py

@@ -1,142 +0,0 @@
-import re
-
-def mid_pas(data, fol_num, include, in_c, toc_y):
-    syntax = 0
-    folding_test = 0
-
-    p = re.compile('{{{((?:(?:(?:\+|-)[0-5])|(?:#|@)(?:(?:[0-9a-f-A-F]{3}){1,2}|(?:\w+))|(?:#!(?:html|wiki|noin|folding|syntax)))(?:(?!{{{|}}}).)+)}}}', re.DOTALL)
-    while 1:
-        m = p.search(data)
-        if m:
-            data = p.sub('###' + m.groups()[0] + '/###', data, 1)
-        else:
-            break
-
-    com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL)
-    while 1:
-        m = com.search(data)
-        if m:
-            data = com.sub('<code>' + m.groups()[0] + '</code>', data, 1)
-        else:
-            break
-
-    com3 = re.compile('###((?:(?!\/###).)+)\/###', re.DOTALL)
-    m = com3.search(data)
-    while 1:
-        m = com3.search(data)
-        if m:
-            data = com3.sub('{{{' + m.groups()[0] + '}}}', data, 1)
-        else:
-            break
-
-    com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
-    da_com = com2.findall(data)
-    for com_da in da_com:
-        mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
-        mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
-        data = com2.sub(mid_data, data, 1)
-
-    while 1:
-        is_it = com.search(data)
-        if is_it:
-            it_d = is_it.groups()[0]
-
-            big_a = re.compile("^\+([1-5]) (.*)$", re.DOTALL)
-            big = big_a.search(it_d)
-
-            small_a = re.compile("^\-([1-5]) (.*)$", re.DOTALL)
-            small = small_a.search(it_d)
-
-            color_b = re.compile("^(#(?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
-            color_2 = color_b.search(it_d)
-
-            color_c = re.compile("^#(\w+) (.*)$", re.DOTALL)
-            color_3 = color_c.search(it_d)
-
-            back_a = re.compile("^@((?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL)
-            back = back_a.search(it_d)
-
-            back_c = re.compile("^@(\w+) (.*)$", re.DOTALL)
-            back_3 = back_c.search(it_d)
-
-            include_out_a = re.compile("^#!noin ?(.*)$", re.DOTALL)
-            include_out = include_out_a.search(it_d)
-
-            div_a = re.compile("^#!wiki style=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\r\n(.*)$", re.DOTALL)
-            div = div_a.search(it_d)
-
-            html_a = re.compile("^#!html ?(.*)$", re.DOTALL)
-            html_d = html_a.search(it_d)
-
-            fol_a = re.compile("^#!folding ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
-            fol = fol_a.search(it_d)
-
-            syn_a = re.compile("^#!syntax ((?:(?!\n).)*)\n(.*)$", re.DOTALL)
-            syn = syn_a.search(it_d)
-
-            if big:
-                big_d = big.groups()
-                data = com.sub('<span style="font-size: ' + str(int(big_d[0]) * 20 + 100) + '%;">' + big_d[1] + '</span>', data, 1)
-            elif small:
-                sm_d = small.groups()
-                data = com.sub('<span style="font-size: ' + str(100 - int(sm_d[0]) * 10) + '%;">' + sm_d[1] + '</span>', data, 1)
-            elif color_2:
-                c_d_2 = color_2.groups()
-                data = com.sub('<span style="color: ' + c_d_2[0] + '">' + c_d_2[1] + '</span>', data, 1)
-            elif color_3:
-                c_d_3 = color_3.groups()
-                data = com.sub('<span style="color: ' + c_d_3[0] + '">' + c_d_3[1] + '</span>', data, 1)
-            elif back:
-                back_d_1 = back.groups()
-                data = com.sub('<span style="background: #' + back_d_1[0] + '">' + back_d_1[1] + '</span>', data, 1)
-            elif back_3:
-                back_d_3 = back_3.groups()
-                data = com.sub('<span style="background: ' + back_d_3[0] + '">' + back_d_3[1] + '</span>', data, 1)
-            elif div:
-                div_d = div.groups()
-                data = com.sub('<div style="' + div_d[0] + '">' + div_d[1] + '</div>', data, 1)
-            elif html_d:
-                data = com.sub(html_d.groups()[0], data, 1)
-            elif fol:
-                fol_d = fol.groups()
-                if toc_y != 0:
-                    data = com.sub("<div>" + fol_d[0] + " <div id='folding_" + str(fol_num + 1) + "' style='display: inline-block;'>" + \
-                                    "[<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + \
-                                    "); folding(" + str(fol_num + 2) + "); folding(" + str(fol_num) + ");'>펼치기</a>]</div>" + \
-                                    "<div id='folding_" + str(fol_num + 2) + "' style='display: none;'>[" + \
-                                    "<a href='javascript:void(0);' onclick='folding(" + str(fol_num + 1) + "); folding(" + str(fol_num + 2) + ");" + \
-                                    " folding(" + str(fol_num) + ");'>접기</a>]</div><div id='folding_" + str(fol_num) + "' style='display: none;'>" + \
-                                    "<br>" + fol_d[1] + "</div></div>", data, 1)
-                    fol_num += 3
-                else:
-                    data = com.sub("<div>" + fol_d[0] + "<br><br>" + fol_d[1] + "</div>", data, 1)
-                
-            elif syn:
-                if syntax == 0:
-                    data += '<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"> \
-                            <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> \
-                            <script>hljs.initHighlightingOnLoad();</script>'
-                    syntax = 1
-
-                syn_d = syn.groups()
-                tax_d = syn_d[1].replace(' ', '<space>')
-                tax_d = tax_d.replace('\r\n', '<isbr>')
-                data = com.sub('<pre id="syntax"><code class="' + syn_d[0] + '"><code>' + tax_d + '</code></code></pre>', data, 1)
-            elif include_out:
-                if (include or in_c) == 1:
-                    data = com.sub("", data, 1)
-                else:
-                    data = com.sub(include_out.groups()[0], data, 1)
-            else:
-                data = com.sub(it_d, data, 1)
-        else:
-            break
-
-    com2 = re.compile("<code>((?:(?!(?:<code>|<\/code>)).)*)<\/code>", re.DOTALL)
-    da_com = com2.findall(data)
-    for com_da in da_com:
-        mid_data = com_da.replace('<', '&lt;').replace('>', '&gt;')
-        mid_data = re.sub("(?P<in>.)", "#no#\g<in>#/no#", mid_data)
-        data = com2.sub(mid_data, data, 1)
-            
-    return [data, fol_num]

+ 0 - 24
set_mark/redirect_pas.py

@@ -1,24 +0,0 @@
-import re
-from urllib import parse
-
-def url_pas(data):
-    return parse.quote(data).replace('/','%2F')
-
-def redirect_pas(data, title, backlink):    
-    d_re = re.findall('\r\n#(?:redirect|넘겨주기) ((?:(?!\r|\n|%0D).)+)', data)
-    for d in d_re:
-        view = d.replace('\\', '')    
-            
-        sh = ''
-        s_d = re.search('#((?:(?!x27;|#).)+)$', d)
-        if s_d:
-            href = re.sub('#((?:(?!x27;|#).)+)$', '', d)
-            sh = '#' + s_d.groups()[0]
-        else:
-            href = d
-            
-        a = href.replace('&#x27;', "'").replace('&quot;', '"').replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
-        backlink += [[title, a, 'redirect']]
-        data = re.sub('\r\n#(?:redirect|넘겨주기) ((?:(?!\r|\n|%0D).)+)', '<meta http-equiv="refresh" content="0;url=/w/' + url_pas(a) + '?froms=' + url_pas(title) + sh + '" />', data, 1)
-        
-    return [data, backlink]

+ 844 - 6
set_mark/start.py

@@ -1,9 +1,847 @@
+from . import tool
+
+import datetime
+import html
 import re
 
-def start(data):    
-    data = data.replace('\\r', '&#92;r')
-    data = data.replace('\\n', '&#92;n')
-    data = re.sub("\n", "\r\n", re.sub("\r\n", "\n", data))
-    data = '\r\n' + data + '\r\n'
+def table_parser(data, cel_data, start_data, num = 0):
+    table_class = 'class="'
+    all_table = 'style="'
+    cel_style = 'style="'
+    row_style = 'style="'
+    row = ''
+    cel = ''
+
+    table_width = re.search("&lt;table ?width=((?:(?!&gt;).)*)&gt;", data)
+    if table_width:
+        all_table += 'width: ' + table_width.groups()[0] + 'px;'
+    
+    table_height = re.search("&lt;table ?height=((?:(?!&gt;).)*)&gt;", data)
+    if table_height:
+        all_table += 'height: ' + table_height.groups()[0] + 'px;'
+    
+    table_align = re.search("&lt;table ?align=((?:(?!&gt;).)*)&gt;", data)
+    if table_align:
+        if table_align.groups()[0] == 'right':
+            all_table += 'float: right;'
+
+        elif table_align.groups()[0] == 'center':
+            all_table += 'margin: auto;'
+            
+    table_text_align = re.search("&lt;table ?textalign=((?:(?!&gt;).)*)&gt;", data)
+    if table_text_align:
+        num = 1
+
+        if table_text_align.groups()[0] == 'right':
+            all_table += 'text-align: right;'
+
+        elif table_text_align.groups()[0] == 'center':
+            all_table += 'text-align: center;'
+
+    row_table_align = re.search("&lt;row ?textalign=((?:(?!&gt;).)*)&gt;", data)
+    if row_table_align:
+        if row_table_align.groups()[0] == 'right':
+            row_style += 'text-align: right;'
+
+        elif row_table_align.groups()[0] == 'center':
+            row_style += 'text-align: center;'
+
+        else:
+            row_style += 'text-align: left;'
+    
+    table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", data)
+    if table_cel:
+        cel = 'colspan="' + table_cel.groups()[0] + '"'
+
+    else:
+        cel = 'colspan="' + str(round(len(start_data) / 2)) + '"'   
+
+    table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", data)
+    if table_row:
+        row = 'rowspan="' + table_row.groups()[0] + '"'
+
+    row_bgcolor = re.search("&lt;rowbgcolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)&gt;", data)
+    if row_bgcolor:
+        row_style += 'background: ' + row_bgcolor.groups()[0] + ';'
+        
+    table_border = re.search("&lt;table ?bordercolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)&gt;", data)
+    if table_border:
+        all_table += 'border: ' + table_border.groups()[0] + ' 2px solid;'
+        
+    table_bgcolor = re.search("&lt;table ?bgcolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)&gt;", data)
+    if table_bgcolor:
+        all_table += 'background: ' + table_bgcolor.groups()[0] + ';'
+        
+    bgcolor = re.search("&lt;(?:bgcolor=)?(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)&gt;", data)
+    if bgcolor:
+        cel_style += 'background: ' + bgcolor.groups()[0] + ';'
+        
+    cel_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", data)
+    if cel_width:
+        cel_style += 'width: ' + cel_width.groups()[0] + 'px;'
+
+    cel_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", data)
+    if cel_height:
+        cel_style += 'height: ' + cel_height.groups()[0] + 'px;'
+        
+    text_right = re.search("&lt;\)&gt;", data)
+    text_center = re.search("&lt;:&gt;", data)
+    text_left = re.search("&lt;\(&gt;",  data)
+    if text_right:
+        cel_style += 'text-align: right;'
+
+    elif text_center:
+        cel_style += 'text-align: center;'
+
+    elif text_left:
+        cel_style += 'text-align: left;'
+
+    elif num == 0:
+        if re.search('^ (.*) $', cel_data):
+            cel_style += 'text-align: center;'
+
+        elif re.search('^ (.*)$', cel_data):
+            cel_style += 'text-align: right;'
+
+        elif re.search('^(.*) $', cel_data):
+            cel_style += 'text-align: left;'
+
+    text_class = re.search("&lt;table ?class=((?:(?!&gt;).)+)&gt;", data)
+    if text_class:
+        table_class += text_class.groups()[0]
+        
+    all_table += '"'
+    cel_style += '"'
+    row_style += '"'
+    table_class += '"'
+
+    return [all_table, row_style, cel_style, row, cel, table_class, num]
+
+def start(conn, data, title):
+    # DB 지정
+    curs = conn.cursor()
+
+    # 초기 설정
+    data = '\n' + data + '\n'
+    backlink = []
+
+    # XSS 이스케이프
+    data = html.escape(data)
+
+    # 포함 문법 처리
+    while 1:
+        include = re.search('\[include\(((?:(?!\)\]).)+)\)\]', data)
+        if include:
+            include = include.groups()[0]
+    
+            include_data = re.search('^((?:(?!,).)+)', include)
+            if include_data:
+                include_data = include_data.groups()[0]
+
+            else:
+                include_data = 'Test'
+
+            include_link = include_data
+
+            backlink += [[title, include_link, 'include']]
+
+            include = re.sub('^((?:(?!,).)+)', '', include)
+
+            curs.execute("select data from data where title = ?", [include_data])
+            include_data = curs.fetchall()
+            if include_data:
+                include_parser = include_data[0][0]
+
+                while 1:
+                    include_plus = re.search(', ?((?:(?!=).)+)=((?:(?!,).)+)', include)
+                    if include_plus:
+                        include_plus = include_plus.groups()
+                        include_parser = re.sub('@' + include_plus[0] + '@', include_plus[1], include_parser)
+
+                        include = re.sub(', ?((?:(?!=).)+)=((?:(?!,).)+)', '', include, 1)
+                    else:
+                        break
+
+                include_parser = re.sub('\[\[분류:(((?!\]\]|#include).)+)\]\]', '', include_parser)
+                include_parser = html.escape(include_parser)
+
+                data = re.sub('\[include\(((?:(?!\)\]).)+)\)\]', '\n' + include_parser + '\n', data, 1)
+
+            else:
+                data = re.sub('\[include\(((?:(?!\)\]).)+)\)\]', '<a id="not_thing" href="/w/' + tool.url_pas(include_link) + '">' + include_link + '</a>', data, 1)
+
+        else:
+            break
+
+    # 개행 정리
+    data = re.sub('\r\n', '\n', data)
+
+    # 표 정리
+    data = re.sub('\n( +)\|\|', '\n||', data)
+    data = re.sub('\|\|( +)\n', '||\n', data)
+
+    # 중괄호 문법 처리
+    middle_stack = 0
+    middle_list = []
+    middle_number = 0
+    while 1:
+        middle_data = re.search('(?:{{{((?:(?! |{{{).)*)|(}}}))', data)
+        if middle_data:
+            middle_data = middle_data.groups()
+            if not middle_data[1]:
+                if middle_stack > 0:
+                    middle_stack += 1
+                    
+                    data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '&#123;&#123;&#123;' + middle_data[0], data, 1)
+
+                else:
+                    check = 0
+                    if check == 0:
+                        middle_search = re.search('^(#(?:[0-9a-f-A-F]{3}){1,2})', middle_data[0])
+                        if middle_search:
+                            check = 1
+                            
+                            middle_search = middle_search.groups()[0]
+                            
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span style="color: ' + middle_search + ';">', data, 1)
+                        
+                        middle_search = re.search('^(?:#(\w+))', middle_data[0])
+                        if middle_search:
+                            check = 1
+                            
+                            middle_search = middle_search.groups()[0]
+                            
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span style="color: ' + middle_search + ';">', data, 1)
+
+                        middle_search = re.search('^(?:@((?:[0-9a-f-A-F]{3}){1,2}))', middle_data[0])
+                        if middle_search:
+                            check = 1
+                            
+                            middle_search = middle_search.groups()[0]
+                            
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span style="background: #' + middle_search + ';">', data, 1)
+                        
+                        middle_search = re.search('^(?:@(\w+))', middle_data[0])
+                        if middle_search:
+                            check = 1
+                            
+                            middle_search = middle_search.groups()[0]
+                            
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span style="background: ' + middle_search + ';">', data, 1)
+
+                        middle_search = re.search('^(\+|-)([1-5])', middle_data[0])
+                        if middle_search:
+                            check = 1
+                            
+                            middle_search = middle_search.groups()
+                            if middle_search[0] == '+':
+                                font_size = str(int(middle_search[1]) * 20 + 100)
+                            else:
+                                font_size = str(100 - int(middle_search[1]) * 10)
+
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span style="font-size: ' + font_size + '%;">', data, 1)
+
+                        middle_search = re.search('^#!wiki', middle_data[0])
+                        if middle_search:
+                            check = 1
+        
+                            middle_data_2 = re.search('{{{#!wiki style=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\n', data)
+                            middle_data_2 = middle_data_2.groups()
+
+                            middle_list += ['div']
+                            
+                            data = re.sub('{{{#!wiki style=(?:&quot;|&#x27;)((?:(?!&quot;|&#x27;).)*)(?:&quot;|&#x27;)\n', '<div style="' + middle_data_2[0] + '">', data, 1)
+
+                        middle_search = re.search('^#!syntax', middle_data[0])
+                        if middle_search:
+                            check = 1
+        
+                            middle_data_2 = re.search('{{{#!syntax ((?:(?!\n).)+)\n', data)
+                            middle_data_2 = middle_data_2.groups()
+
+                            middle_list += ['code', 'pre']
+                            middle_number += 1
+                            
+                            data = re.sub('{{{#!syntax ((?:(?!\n).)+)\n', '<pre id="syntax"><code class="' + middle_data_2[0] + '">', data, 1)
+
+                        middle_search = re.search('^#!html', middle_data[0])
+                        if middle_search:
+                            check = 1
+
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span>', data, 1)
+
+                        middle_search = re.search('^#!folding', middle_data[0])
+                        if middle_search:
+                            check = 1
+
+                            middle_list += ['span']
+                            
+                            data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<span>', data, 1)
+
+                    if not check == 1:
+                        middle_list += ['code']
+                        
+                        middle_stack += 1
+                        
+                        data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '<code>' + middle_data[0], data, 1)
+                
+                    middle_number += 1
+
+            else:
+                if middle_stack > 0:
+                    middle_stack -= 1
+
+                if middle_stack > 0:
+                    data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '&#125;&#125;&#125;', data, 1)
+
+                else:
+                    if middle_number > 0:
+                        middle_number -= 1
+
+                    if middle_list[middle_number] == 'pre':
+                        data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '</code></pre>', data, 1)
+
+                        del(middle_list[middle_number])
+                        middle_number -= 1
+                    else:
+                        data = re.sub('(?:{{{((?:(?! |{{{).)*)|(}}}))', '</' + middle_list[middle_number] + '>', data, 1)
+                    
+                    del(middle_list[middle_number])
+
+        else:
+            break
+
+    # 추가 데이터 지정
+    plus_data = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script><script>hljs.initHighlightingOnLoad();</script>'
+
+    # NoWiki 처리
+    num = 0
+    while 1:
+        nowiki_data = re.search('<code>((?:(?:(?!<\/code>).)+\n*)+)<\/code>', data)
+        if nowiki_data:
+            nowiki_data = nowiki_data.groups()
+
+            num += 1
+
+            plus_data += '<script>function func_nowiki_' + str(num) + '() { document.all("nowiki_' + str(num) + '").innerHTML = "' + nowiki_data[0] + '"; }</script>'
+
+            data = re.sub('<code>((?:(?:(?!<\/code>).)+\n*)+)<\/code>', '<a href="javascript:void(0);" onclick="func_nowiki_' + str(num) + '();" id="nowiki_' + str(num) + '">(NoWiki 보기)</a>', data, 1)
+
+        else:
+            break
+
+    # Syntax 처리
+    while 1:
+        syntax_data = re.search('<code class="((?:(?!").)+)">((?:(?:(?!<\/code>|<span id="space">).)+\n*)+)<\/code>', data)
+        if syntax_data:
+            syntax_data = syntax_data.groups()
+
+            syntax_data_replace = syntax_data[1]
+
+            while 1:
+                syntax_space = re.search('\n( +)', syntax_data_replace)
+                if syntax_space:
+                    syntax_space = syntax_space.groups()
+
+                    space_len = '\n<span id="space">' + syntax_space[0] + '</span>'
+
+                    syntax_data_replace = re.sub('\n( +)', space_len, syntax_data_replace, 1)
+
+                else:
+                    break             
+
+            data = re.sub('<code class="((?:(?!").)+)">((?:(?:(?!<\/code>).)+\n*)+)<\/code>', '<code class="' + syntax_data[0] + '">' + syntax_data_replace + '</code>', data, 1)
+        
+        else:
+            break
+
+    print(data)
+
+    # 수식 처리
+    first = 0
+    while 1:
+        math = re.search('&lt;math&gt;((?:(?!&lt;\/math&gt;).)+)&lt;\/math&gt;', data)
+        if math:
+            if first == 0:
+                plus_data += '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/katex.min.css" integrity="sha384-TEMocfGvRuD1rIAacqrknm5BQZ7W7uWitoih+jMNFXQIbNl16bO8OZmylH/Vi/Ei" crossorigin="anonymous"><script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0/katex.min.js" integrity="sha384-jmxIlussZWB7qCuB+PgKG1uLjjxbVVIayPJwi6cG6Zb4YKq0JIw+OMnkkEC7kYCq" crossorigin="anonymous"></script>'
+
+            math = math.groups()[0]
+            
+            first += 1
+            
+            data = re.sub('&lt;math&gt;((?:(?!&lt;\/math&gt;).)+)&lt;\/math&gt;', '<span id="math_' + str(first) + '"></span>', data, 1)
+
+            plus_data += '<script>katex.render("' + math.replace('\\', '\\\\') +'", document.getElementById("math_' + str(first) + '"));</script>'
+        
+        else:
+            break
+
+    # 추가 이스케이프
+    data = data.replace('\\', '&#92;')
+
+    # 텍스트 꾸미기 문법
+    data = re.sub('&#x27;&#x27;&#x27;(?P<in>((?!&#x27;&#x27;&#x27;).)+)&#x27;&#x27;&#x27;', '<b>\g<in></b>', data)
+    data = re.sub('&#x27;&#x27;(?P<in>((?!&#x27;&#x27;).)+)&#x27;&#x27;', '<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)
+
+    # 넘겨주기 변환
+    while 1:
+        redirect = re.search('\n#(?:redirect|넘겨주기) ((?:(?!\n).)+)\n', data)
+        if redirect:
+            redirect = redirect.groups()[0]
+            
+            backlink += [[title, redirect, 'redirect']]
+            
+            data = re.sub('\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\n).)+)\n', '<meta http-equiv="refresh" content="0; url=/w/\g<in>?froms=' + tool.url_pas(title) + '">', data, 1)
+
+        else:
+            break
+
+    # [목차(없음)] 처리
+    if not re.search('\[목차\(없음\)\]\n', data):
+        if not re.search('\[목차\]', data):
+            data = re.sub('\n(?P<in>={1,6}) ?(?P<out>(?:(?!=).)+) ?={1,6}\n', '\n[목차]\n\g<in> \g<out> \g<in>\n', data, 1)
+
+    else:
+        data = re.sub('\[목차\(없음\)\]\n', '', data)
+
+    # 문단 문법
+    toc_full = 0
+    toc_top_stack = 6
+    toc_stack = [0, 0, 0, 0, 0, 0]
+    edit_number = 0
+    toc_data = '<div id="toc"><span style="font-size: 18px;">목차</span>\n\n'
+    while 1:
+        toc = re.search('\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\n', data)
+        if toc:
+            toc = toc.groups()
+            
+            toc_number = len(toc[0])
+            edit_number += 1
+
+            # 더 크면 그 전 스택은 초기화
+            if toc_full > toc_number:
+                for i in range(toc_number, 6):
+                    toc_stack[i] = 0
+
+            if toc_top_stack > toc_number:
+                toc_top_stack = toc_number
+                    
+            toc_full = toc_number        
+            toc_stack[toc_number - 1] += 1
+            toc_number = str(toc_number)
+            all_stack = ''
+
+            # 스택 합치기
+            for i in range(0, 6):
+                all_stack += str(toc_stack[i]) + '.'
+
+            all_stack = re.sub('0.', '', all_stack)
+            
+            data = re.sub('\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\n', '\n<h' + toc_number + ' id="s-' + re.sub('\.$', '', all_stack) + '"><a href="#toc">' + all_stack + '</a> ' + toc[1] + ' <span style="font-size: 12px"><a href="/edit/' + tool.url_pas(title) + '?section=' + str(edit_number) + '">(편집)</a></span></h' + toc_number + '>\n', data, 1)
+            
+            toc_data += '<span style="margin-left: ' + str((toc_full - toc_top_stack) * 10) + 'px;"><a href="#s-' + re.sub('\.$', '', all_stack) + '">' + all_stack + '</a> ' + toc[1] + '</span>\n'
+        
+        else:
+            break
+
+    toc_data += '</div>'
+    
+    data = re.sub('\[목차\]', toc_data, data)
+    
+    while 1:
+        hr = re.search('\n-{4,9}\n', data)
+        if hr:
+            data = re.sub('\n-{4,9}\n', '\n<hr>\n', data, 1)
+        
+        else:
+            break
+
+    data += '\n'
+
+    # 일부 매크로 처리
+    data = tool.savemark(data)
+    
+    data = re.sub("\[br\]", '\n', data)
+    data = re.sub("\[anchor\((?P<in>(?:(?!\)\]).)+)\)\]", '<span id="\g<in>"></span>', data)          
+    data = re.sub("\[nicovideo\((?P<in>(?:(?!,|\)\]).)+)(?:(?:(?!\)\]).)*)\)\]", "[[http://embed.nicovideo.jp/watch/\g<in>|\g<in>]]", data)
+    data = re.sub('\[ruby\((?P<in>(?:(?!,).)+)\, ?(?P<out>(?:(?!\)\]).)+)\)\]', '<ruby>\g<in><rp>(</rp><rt>\g<out></rt><rp>)</rp></ruby>', data)
+
+    # 원래 코드 재탕
+    now_time = tool.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:
+        old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
+        will = datetime.datetime.strptime(age, '%Y-%m-%d')
+        
+        e_data = old - will
         
-    return data
+        data = re.sub('\[age\(([0-9]{4})-([0-9]{2})-([0-9]{2})\)\]', str(int(int(e_data.days) / 365)), data, 1)
+
+    dday_data = re.findall('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', data)
+    for dday in dday_data:
+        old = datetime.datetime.strptime(time[0], '%Y-%m-%d')
+        will = datetime.datetime.strptime(dday, '%Y-%m-%d')
+        
+        e_data = old - will
+        
+        if re.search('^-', str(e_data.days)):
+            e_day = str(e_data.days)
+
+        else:
+            e_day = '+' + str(e_data.days)
+
+        data = re.sub('\[dday\(([0-9]{4}-[0-9]{2}-[0-9]{2})\)\]', e_day, data, 1)
+
+    # 유튜브, 카카오 티비 처리
+    while 1:
+        video = re.search('\[(youtube|kakaotv)\(((?:(?!\)\]).)+)\)\]', data)
+        if video:
+            video = video.groups()
+            
+            width = re.search(', ?width=((?:(?!,).)+)', video[1])
+            if width:
+                video_width = width.groups()[0]
+
+            else:
+                video_width = '560'
+            
+            height = re.search(', ?height=((?:(?!,).)+)', video[1])
+            if height:
+                video_height = height.groups()[0]
+
+            else:
+                video_height = '315'
+
+            code = re.search('^(((?!,).)+)', video[1])
+            if code:
+                video_code = code.groups()[0]
+
+            else:
+                if video[0] == 'youtube':
+                    video_code = 'BQ5PcIUcdUE'
+
+                else:
+                    video_code = '66861302'
+
+            if video[0] == 'youtube':
+                video_code = re.sub('^https:\/\/www\.youtube\.com\/watch\?v=', '', video_code)
+                video_code = re.sub('^https:\/\/youtu\.be\/', '', video_code)
+                
+                video_src = 'https://www.youtube.com/embed/' + video_code
+
+            else:
+                video_code = re.sub('^https:\/\/tv\.kakao\.com\/channel\/9262\/cliplink\/', '', video_code)
+                video_code = re.sub('^http:\/\/tv\.kakao\.com\/v\/', '', video_code)
+                
+                video_src = 'https://tv.kakao.com/embed/player/cliplink/' + video_code +'?service=kakao_tv'
+                
+            data = re.sub('\[(youtube|kakaotv)\(((?:(?!\)\]).)+)\)\]', '<iframe width="' + video_width + '" height="' + video_height + '" src="' + video_src + '" allowfullscreen frameborder="0"></iframe>', data, 1)
+
+        else:
+            break
+
+    # 인용문 구현
+    while 1:
+        block = re.search('(\n(?:&gt; ?(?:(?:(?!\n).)+)?\n)+)', data)
+        if block:
+            block = block.groups()[0]
+            
+            block = re.sub('^\n&gt; ?', '', block)
+            block = re.sub('\n&gt; ?', '\n', block)
+            block = re.sub('\n$', '', block)
+            
+            data = re.sub('(\n(?:&gt; ?(?:(?:(?!\n).)+)?\n)+)', '\n<blockquote>' + block + '</blockquote>\n', data, 1)
+
+        else:
+            break
+
+    # 리스트 구현
+    while 1:
+        li = re.search('(\n(?:(?: *)\* ?(?:(?:(?!\n).)+)\n)+)', data)
+        if li:
+            li = li.groups()[0]
+            while 1:
+                sub_li = re.search('\n(?:( *)\* ?((?:(?!\n).)+))', li)
+                if sub_li:
+                    sub_li = sub_li.groups()
+
+                    # 앞의 공백 만큼 margin 먹임
+                    if len(sub_li[0]) == 0:
+                        margin = 20
+
+                    else:
+                        margin = len(sub_li[0]) * 20
+
+                    li = re.sub('\n(?:( *)\* ?((?:(?!\n).)+))', '<li style="margin-left: ' + str(margin) + 'px;">' + sub_li[1] + '</li>', li, 1)
+
+                else:
+                    break
+
+            data = re.sub('(\n(?:(?: *)\* ?(?:(?:(?!\n).)+)\n)+)', '\n\n<ul>' + li + '</ul>\n', data, 1)
+
+        else:
+            break
+
+    # 들여쓰기 구현
+    while 1:
+        indent = re.search('\n( +)', data)
+        if indent:
+            indent = len(indent.groups()[0])
+            
+            # 앞에 공백 만큼 margin 먹임
+            margin = '<span style="margin-left: 20px;"></span>' * indent
+            
+            data = re.sub('\n( +)', '\n' + margin, data, 1)
+
+        else:
+            break
+
+    # 표 처리
+    while 1:
+        table = re.search('\n((?:(?:(?:(?:\|\|)+(?:(?:(?!\|\|).(?:\n)*)+))+)\|\|(?:\n)?)+)', data)
+        if table:
+            table = table.groups()[0]
+            
+            # return [all_table, row_style, cel_style, row, cel, table_class, num]
+            while 1:
+                all_table = re.search('^((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)((?:(?!\|\||<\/td>).)+)', table)
+                if all_table:
+                    all_table = all_table.groups()
+                    
+                    return_table = table_parser(all_table[1], all_table[2], all_table[0])
+                    
+                    number = return_table[6]
+                    
+                    table = re.sub('^((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)', '\n<table ' + return_table[5] + ' ' + return_table[0] + '><tbody><tr ' + return_table[1] + '><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>\n', table, 1)
+
+                else:
+                    break
+
+            table = re.sub('\|\|\n$', '</td></tr></tbody></table>', table)
+            while 1:
+                row_table = re.search('\|\|\n((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)((?:(?!\|\||<\/td>).)+)', table)
+                if row_table:
+                    row_table = row_table.groups()
+                    
+                    return_table = table_parser(row_table[1], row_table[2], row_table[0], number)
+                    
+                    table = re.sub('\|\|\n((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)', '</td></tr><tr ' + return_table[1] + '><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>', table, 1)
+
+                else:
+                    break
+
+            while 1:
+                cel_table = re.search('((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)((?:(?:(?!\|\||<\/td>).)|\n)+)', table)
+                if cel_table:
+                    cel_table = cel_table.groups()
+                    
+                    return_table = table_parser(cel_table[1], re.sub('\n', ' ', cel_table[2]), cel_table[0], number)
+                    
+                    table = re.sub('((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)', '</td><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>', table, 1)
+
+                else:
+                    break
+
+            data = re.sub('\n((?:(?:(?:(?:\|\|)+(?:(?:(?!\|\|).(?:\n)*)+))+)\|\|(?:\n)?)+)', table, data, 1)
+        else:
+            break
+
+    # 링크 관련 문법 구현
+    category = '\n<hr><div id="cate">분류: '
+    while 1:
+        link = re.search('\[\[((?:(?!\[\[|\]\]).)+)\]\]', data)
+        if link:
+            link = link.groups()[0]
+            
+            link_split = re.search('((?:(?!\|).)+)(?:\|((?:(?!\|).)+))', link)
+            if link_split:
+                link_split = link_split.groups()
+                
+                main_link = link_split[0]
+                see_link = link_split[1]
+
+            else:
+                main_link = link
+                see_link = link
+
+            if re.search('^(파일|외부):', main_link):
+                width = re.search('width=((?:(?!,).)+)', see_link)
+                if width:
+                    file_width = width.groups()[0]
+
+                else:
+                    file_width = 'auto'
+                
+                height = re.search('height=((?:(?!,).)+)', see_link)
+                if height:
+                    file_height = height.groups()[0]
+
+                else:
+                    file_height = 'auto'
+
+                align = re.search('align=((?:(?!,).)+)', see_link)
+                if align:
+                    file_align = align.groups()[0]
+                    if file_align == 'center':
+                        file_align = 'display: block; text-align: center;'
+
+                    else:
+                        file_align = 'float: ' + file_align + ';'
+
+                else:
+                    file_align = ''
+
+                if re.search('^외부:', main_link):
+                    file_src = re.sub('^외부:', '', main_link)
+            
+                    file_alt = main_link
+
+                else:
+                    file_data = re.search('^파일:((?:(?!\.).)+)\.(.+)$', main_link)
+                    if file_data:
+                        file_data = file_data.groups()
+                        file_name = file_data[0]
+                        file_end = file_data[1]
+
+                        backlink += [[title, main_link, 'file']]
+
+                    else:
+                        file_name = 'TEST'
+                        file_end = 'jpg'
+
+                    file_src = '/image/' + tool.sha224(file_name) + '.' + file_end
+                    file_alt = '파일:' + file_name + '.' + file_end
+                
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '<span style="' + file_align + '"><img width="' + file_width + '" height="' + file_height + '" alt="' + file_alt + '" src="' + file_src + '"></span>', data, 1)
+
+            elif re.search('^분류:', main_link):
+                see_link = re.sub('#include', '', see_link)
+                main_link = re.sub('#include', '', main_link)
+
+                if re.search('#blur', main_link):
+                    see_link = '스포일러'
+                    link_id = 'id="inside"'
+                    
+                    main_link = re.sub('#blur', '', main_link)
+
+                else:
+                    link_id = ''
+
+                backlink += [[title, main_link, 'cat']]
+
+                category += '<a ' + link_id + ' href="' + tool.url_pas(main_link) + '">' + re.sub('^분류:', '', see_link) + '</a> / '
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '', data, 1)
+
+            elif re.search('^wiki:', main_link):
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '<a id="inside" href="/' + tool.url_pas(re.sub('^wiki:', '', main_link)) + '">' + see_link + '</a>', data, 1)
+
+            elif re.search('^http(s)?:\/\/', main_link):
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '<a id="out_link" rel="nofollow" href="' + main_link + '">' + see_link + '</a>', data, 1)
+
+            else:
+                if re.search('^:', main_link):
+                    main_link = re.sub('^:', '', main_link)
+
+                curs.execute("select title from data where title = ?", [main_link])
+                if not curs.fetchall():
+                    link_id = 'id="not_thing"'
+
+                    backlink += [[title, main_link, 'no']]
+
+                else:
+                    link_id = ''
+
+                backlink += [[title, main_link, '']]
+
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '<a ' + link_id + ' href="/w/' + tool.url_pas(main_link) + '">' + see_link + '</a>', data, 1)
+        else:
+            break
+
+    # 각주 처리
+    footnote_number = 0
+    footnote_all = '\n<hr><ul id="footnote_data">'
+    footnote_dict = {}
+    while 1:
+        footnote = re.search('(?:\[\*((?:(?! |\]).)*)(?: ((?:(?!\]).)+))?\]|(\[각주\]))', data)
+        if footnote:
+            footnote_data = footnote.groups()
+            if footnote_data[2]:
+                footnote_all += '</ul>'
+                
+                data = re.sub('(?:\[\*((?:(?! ).)*) ((?:(?!\]).)+)\]|(\[각주\]))', footnote_all, data, 1)
+                
+                footnote_all = '\n<hr><ul id="footnote_data">'
+
+            else:
+                footnote = footnote_data[1]
+                footnote_name = footnote_data[0]
+                if footnote_name and not footnote:
+                    data = re.sub('(?:\[\*((?:(?! |\]).)*)(?: ((?:(?!\]).)+))?\]|(\[각주\]))', '<sup><a href="#fn-' + footnote_dict[footnote_name] + '" id="rfn-' + footnote_dict[footnote_name] + '">(' + footnote_name + ')</a></sup>', data, 1)
+
+                else:
+                    footnote_number += 1
+
+                    if not footnote_name:
+                        footnote_name = str(footnote_number)
+                    else:
+                        footnote_dict.update({ footnote_name : str(footnote_number) })
+
+                    footnote_all += '<li><a href="#rfn-' + str(footnote_number) + '" id="fn-' + str(footnote_number) + '">(' + footnote_name + ')</a> ' + footnote + '</li>'
+                    
+                    data = re.sub('(?:\[\*((?:(?! |\]).)*)(?: ((?:(?!\]).)+))?\]|(\[각주\]))', '<sup><a href="#fn-' + str(footnote_number) + '" id="rfn-' + str(footnote_number) + '">(' + footnote_name + ')</a></sup>', data, 1)
+                    
+        else:
+            break
+
+    footnote_all += '</ul>'
+    if footnote_all == '\n<hr><ul id="footnote_data"></ul>':
+        footnote_all = ''
+
+    data = re.sub('\n$', footnote_all, data, 1)
+
+    # 분류 마지막 처리
+    category += '</div>'
+    category = re.sub(' / <\/div>$', '</div>', category)
+
+    if category == '\n<hr><div id="cate">분류: </div>':
+        category = ''
+
+    if data != '\n\n':
+        data += category
+
+    else:
+        data = re.sub('\n<hr>', '', category)
+    
+    # 마지막 처리
+    data = re.sub('(?P<in><\/h[0-9]>)(\n)+', '\g<in>', data)
+    data = re.sub('<\/ul>\n\n', '</ul>\n', data)
+    data = re.sub('^(\n)+', '', data)
+    data = re.sub('(\n)+<hr><ul id="footnote_data">', '<hr><ul id="footnote_data">', data)
+    data = re.sub('(?P<in><td(((?!>).)*)>)\n', '\g<in>', data)
+    data = re.sub('(\n)?<hr>(\n)?', '<hr>', data)
+    data = re.sub('\n', '<br>', data)
+
+    return [data, plus_data, backlink]

+ 0 - 250
set_mark/table.py

@@ -1,250 +0,0 @@
-import re
-
-def table_p(d, d2, d3, num = 0):
-    table_class = 'class="'
-    alltable = 'style="'
-    celstyle = 'style="'
-    rowstyle = 'style="'
-    row = ''
-    cel = ''
-
-    table_w = re.search("&lt;table\s?width=((?:(?!&gt;).)*)&gt;", d)
-    table_h = re.search("&lt;table\s?height=((?:(?!&gt;).)*)&gt;", d)
-    table_a = re.search("&lt;table\s?align=((?:(?!&gt;).)*)&gt;", d)
-    if table_w:
-        alltable += 'width: ' + table_w.groups()[0] + ';'
-    if table_h:
-        alltable += 'height: ' + table_h.groups()[0] + ';'
-    if table_a:
-        if table_a.groups()[0] == 'right':
-            alltable += 'float: right;'
-        elif table_a.groups()[0] == 'center':
-            alltable += 'margin: auto;'
-            
-    table_t_a = re.search("&lt;table\s?textalign=((?:(?!&gt;).)*)&gt;", d)
-    if table_t_a:
-        num = 1
-        if table_t_a.groups()[0] == 'right':
-            alltable += 'text-align: right;'
-        elif table_t_a.groups()[0] == 'center':
-            alltable += 'text-align: center;'
-
-    row_t_a = re.search("&lt;row\s?textalign=((?:(?!&gt;).)*)&gt;", d)
-    if row_t_a:
-        if row_t_a.groups()[0] == 'right':
-            rowstyle += 'text-align: right;'
-        elif row_t_a.groups()[0] == 'center':
-            rowstyle += 'text-align: center;'
-        else:
-            rowstyle += 'text-align: left;'
-    
-    table_cel = re.search("&lt;-((?:(?!&gt;).)*)&gt;", d)
-    if table_cel:
-        cel = 'colspan="' + table_cel.groups()[0] + '"'
-    else:
-        cel = 'colspan="' + str(round(len(d2) / 2)) + '"'   
-
-    table_row = re.search("&lt;\|((?:(?!&gt;).)*)&gt;", d)
-    if table_row:
-        row = 'rowspan="' + table_row.groups()[0] + '"'
-
-    row_bgcolor_2 = re.search("&lt;rowbgcolor=(#(?:[0-9a-f-A-F]{3}){1,2})&gt;", d)
-    row_bgcolor_3 = re.search("&lt;rowbgcolor=(\w+)&gt;", d)
-    if row_bgcolor_2:
-        rowstyle += 'background: ' + row_bgcolor_2.groups()[0] + ';'
-    elif row_bgcolor_3:
-        rowstyle += 'background: ' + row_bgcolor_3.groups()[0] + ';'
-        
-    table_border_2 = re.search("&lt;table\s?bordercolor=(#(?:[0-9a-f-A-F]{3}){1,2})&gt;", d)
-    table_border_3 = re.search("&lt;table\s?bordercolor=(\w+)&gt;", d)
-    if table_border_2:
-        alltable += 'border: ' + table_border_2.groups()[0] + ' 2px solid;'
-    elif table_border_3:
-        alltable += 'border: ' + table_border_3.groups()[0] + ' 2px solid;'
-        
-    table_bgcolor_2 = re.search("&lt;table\s?bgcolor=(#(?:[0-9a-f-A-F]{3}){1,2})&gt;", d)
-    table_bgcolor_3 = re.search("&lt;table\s?bgcolor=(\w+)&gt;", d)
-    if table_bgcolor_2:
-        alltable += 'background: ' + table_bgcolor_2.groups()[0] + ';'
-    elif table_bgcolor_3:
-        alltable += 'background: ' + table_bgcolor_3.groups()[0] + ';'
-        
-    bgcolor_2 = re.search("&lt;(?:bgcolor=)?(#(?:[0-9a-f-A-F]{3}){1,2})&gt;", d)
-    bgcolor_3 = re.search("&lt;(?:bgcolor=)?(\w+)&gt;", d)
-    if bgcolor_2:
-        celstyle += 'background: ' + bgcolor_2.groups()[0] + ';'
-    elif bgcolor_3:
-        celstyle += 'background: ' + bgcolor_3.groups()[0] + ';'
-        
-    n_width = re.search("&lt;width=((?:(?!&gt;).)*)&gt;", d)
-    n_height = re.search("&lt;height=((?:(?!&gt;).)*)&gt;", d)
-    if n_width:
-        celstyle += 'width: ' + n_width.groups()[0] + ';'
-    if n_height:
-        celstyle += 'height: ' + n_height.groups()[0] + ';'
-        
-    text_right = re.search("&lt;\)&gt;", d)
-    text_center = re.search("&lt;:&gt;", d)
-    text_left = re.search("&lt;\(&gt;",  d)
-    if text_right:
-        celstyle += 'text-align: right;'
-    elif text_center:
-        celstyle += 'text-align: center;'
-    elif text_left:
-        celstyle += 'text-align: left;'
-    elif num == 0:
-        if re.search('^ (.*) $', d3):
-            celstyle += 'text-align: center;'
-        elif re.search('^ (.*)$', d3):
-            celstyle += 'text-align: right;'
-        elif re.search('^(.*) $', d3):
-            celstyle += 'text-align: left;'
-
-    text_class = re.search("&lt;table\s?class=((?:(?!&gt;).)+)&gt;", d)
-    if text_class:
-        d = text_class.groups()
-        table_class += d[0]
-        
-    alltable += '"'
-    celstyle += '"'
-    rowstyle += '"'
-    table_class += '"'
-
-    return [alltable, rowstyle, celstyle, row, cel, table_class, num]
-
-def table(data):
-    data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
-        
-    while 1:
-        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 1:
-        m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
-        if m:
-            results = m.groups()
-            table = results[0]
-            while 1:
-                a = re.search("^(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\||<\/td>).)*)", table)
-                if a:
-                    row = ''
-                    cel = ''
-                    celstyle = ''
-                    rowstyle = ''
-                    alltable = ''
-                    table_d = ''
-                    num = 0
-
-                    result = a.groups()
-                    if result[1]:
-                        table_d = table_p(result[1], result[0], result[2])
-                        alltable = table_d[0]
-                        rowstyle = table_d[1]
-                        celstyle = table_d[2]
-                        row = table_d[3]
-                        cel = table_d[4]
-                        table_class = table_d[5]
-                        num = table_d[6]
-                            
-                        table = re.sub("^(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "<table " + table_class + " " + alltable + "><tbody><tr " + rowstyle + \
-                                        "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
-                    else:
-                        cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
-
-                        if re.search('^ (.*) $', result[2]):
-                            celstyle += 'text-align: center;'
-                        elif re.search('^ (.*)$', result[2]):
-                            celstyle += 'text-align: right;'
-                        elif re.search('^(.*) $', result[2]):
-                            celstyle += 'text-align: left;'
-
-                        table = re.sub("^(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "<table><tbody><tr><td " + cel + " style='" + celstyle + "'>", table, 1)
-                else:
-                    break
-                    
-            table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
-            
-            while 1:
-                b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\||<\/td>).)*)", table)
-                if b:
-                    row = ''
-                    cel = ''
-                    celstyle = ''
-                    rowstyle = ''
-                    table_d = ''
-
-                    result = b.groups()
-                    if result[1]:
-                        table_d = table_p(result[1], result[0], result[2], num)
-                        rowstyle = table_d[1]
-                        celstyle = table_d[2]
-                        row = table_d[3]
-                        cel = table_d[4]
-                        
-                        table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "</td></tr><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
-                    else:
-                        cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
-
-                        if re.search('^ (.*) $', result[2]):
-                            celstyle += 'text-align: center;'
-                        elif re.search('^ (.*)$', result[2]):
-                            celstyle += 'text-align: right;'
-                        elif re.search('^(.*) $', result[2]):
-                            celstyle += 'text-align: left;'
-
-                        table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "</td></tr><tr><td " + cel + " style='" + celstyle + "'>", table, 1)
-                else:
-                    break
-
-            while 1:
-                c = re.search("(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\||<\/td>).)*)", table)
-                if c:
-                    row = ''
-                    cel = ''
-                    celstyle = ''
-                    table_d = ''
-
-                    result = c.groups()
-                    if result[1]:
-                        table_d = table_p(result[1], result[0], result[2], num)
-                        celstyle = table_d[2]
-                        row = table_d[3]
-                        cel = table_d[4]
-
-                        table = re.sub("(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "</td><td " + cel + " " + row + " " + celstyle + ">", table, 1)
-                    else:
-                        cel = 'colspan="' + str(round(len(result[0]) / 2)) + '"'
-
-                        if re.search('^ (.*) $', result[2]):
-                            celstyle += 'text-align: center;'
-                        elif re.search('^ (.*)$', result[2]):
-                            celstyle += 'text-align: right;'
-                        elif re.search('^(.*) $', result[2]):
-                            celstyle += 'text-align: left;'
-
-                        table = re.sub("(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", \
-                                        "</td><td " + cel + " style='" + celstyle + "'>", table, 1)
-                else:
-                    break
-            
-            data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
-        else:
-            break
-        
-    return data

+ 0 - 19
set_mark/text_help.py

@@ -1,19 +0,0 @@
-import re
-
-def text_help(data):    
-    data = re.sub("&#x27;&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;&#x27;).)*)&#x27;&#x27;&#x27;", '<b>\g<in></b>', data)
-    data = re.sub("&#x27;&#x27;(?P<in>(?:(?!&#x27;&#x27;).)*)&#x27;&#x27;", '<i>\g<in></i>', 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)
-
-    if re.search('&lt;math&gt;((?:(?!&lt;\/math&gt;).)*)&lt;\/math&gt;', data):
-        data = re.sub('&lt;math&gt;(?P<in>(?:(?!&lt;\/math&gt;).)*)&lt;\/math&gt;', '[math]\g<in>[/math]', data)
-        data += '<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: { inlineMath: [ [\'[math]\', \'[/math]\'] ] } });</script> \
-                <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-AMS_CHTML"></script>'
- 
-    data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
-    data = re.sub("-{4,11}", "<hr>", data)
-        
-    return data

+ 0 - 84
set_mark/toc_pas.py

@@ -1,84 +0,0 @@
-import re
-from urllib import parse
-
-def url_pas(data):
-    return parse.quote(data).replace('/','%2F')
-
-def toc_pas(data, title, num, toc_y):
-    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
-    toc_c = -1
-    toc_d = -1
-    span = ''
-    rtoc = '<div id="toc"><span id="toc-name">목차</span><br><br>'
-    while 1:
-        i[0] += 1
-        m = re.search('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\r\n', data)
-        if m:
-            result = m.groups()
-            wiki = len(result[0])
-            if last < wiki:
-                last = wiki
-            else:
-                last = wiki
-                for a in range(wiki + 1, 7):
-                    i[a] = 0
-            
-            i[wiki] += 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)
-
-            if toc_c == -1:
-                margin = ''
-                toc_c = toc.count('.')
-            else:
-                toc_d = toc.count('.')
-                if toc_c == toc_d:
-                    margin = 'style="margin-top: 30px;"'
-                else:
-                    if toc_d < toc_c:
-                        margin = 'style="margin-top: 30px;"'
-                    else:
-                        margin = 'style="margin-top: 15px;"'
-                    
-                    toc_c = toc_d
-
-            t = toc.count('.')
-            span = '<span style="margin-left: 5px;"></span>' * t
-
-            rtoc += span + '<a href="#s-' + toc + '">' + toc + '</a>. ' + re.sub('(?:\[\*([^\s]*)(?:\s((?:(?!\[|\]).)*))?\])', '', result[1]) + '<br>'
-
-            c = re.sub(" $", "", result[1])
-            d = c
-            c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
-            c = re.sub('(?:\[\*([^\s]*)(?:\s((?:(?!\[|\]).)*))?\])', '', c)
-
-            edit_d = ''
-            if toc_y == 1:
-                edit_d = ' <span style="font-size: 12px;"><a href="/edit/' + url_pas(title) + '?section=' + str(i[0]) + '">(편집)</a></span>'
-
-            data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' \
-                                                                         + toc + '.<span style="margin-left: 5px;"></span></a> ' \
-                                                                         + d + edit_d + '</h' + str(wiki) + '><hr id="under_bar" style="margin-top: -5px;">\n', data, 1)
-        else:
-            rtoc += '</div>'
-            
-            break
-    
-    data = re.sub("\[목차\]", rtoc, data)
-
-    return data

+ 43 - 0
set_mark/tool.py

@@ -0,0 +1,43 @@
+from flask import session, request
+
+from urllib import parse
+import time
+import datetime
+import re
+import json
+import hashlib
+
+def get_time():
+    now = time.localtime()
+    date = "%04d-%02d-%02d %02d:%02d:%02d" % (now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)
+
+    return date
+    
+def ip_check():
+    if session and ('Now' and 'DREAMER') in session and session['Now'] == 1:
+        ip = session['DREAMER']
+    else:
+        try:
+            ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
+        except:
+            ip = 'None'
+
+    return str(ip)
+
+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 url_pas(data):
+    return parse.quote(data).replace('/','%2F')
+
+def sha224(data):
+    return hashlib.sha224(bytes(data, 'utf-8')).hexdigest()

+ 6 - 2
version.md

@@ -132,7 +132,7 @@
  * 파일 시스템 개선
  * 잡 패치
 
-## 2.6 (Flask) (진행)
+## 2.6 (Flask)
  * 기반 구조 개편
  * 분류 구조 개편
  * 디자인 수정
@@ -140,6 +140,10 @@
  * 재 인덱싱 추가
  * 디자인 수정
 
+## 3.0 (진행)
+ * 파서 다시 작성
+ * 사소한 기능 변경
+
 ## 자세한 내용
  * [참조](https://github.com/2DU/openNAMU/commits/master)
 
@@ -160,7 +164,7 @@
 
 ----
 ## 기타
- * 현재 버전 : v2.6.5 Beta
+ * 현재 버전 : v3.0.0
 
 ----
 ## 개발 이념

+ 9 - 5
views/acme/css/style-responsive.css

@@ -47,7 +47,7 @@
     }
 
     .navbar-toggle {
-        margin-right: -10px;
+        margin-right: 0px;
     }
 
     .head-section .nav li .dropdown-menu li a:hover {
@@ -57,6 +57,7 @@
     .navbar-brand {
         margin-top: 10px !important;
         float: left !important;
+        line-height: 40px;
     }
 }
 
@@ -76,7 +77,7 @@ ul {
     text-decoration: none;
 }
 
-label, span, body, strong, b, div, h1, h2, h3, h4, h5, h6, h7, input { 
+label, span, body, strong, b, div, h1, h2, h3, h4, h5, h6, input { 
     font-family: "helvetica", "Noto Sans Japanese", "나눔고딕", "맑은 고딕", "Nanum Gothic", "sans-serif"; 
 }
 
@@ -210,6 +211,7 @@ input {
 
 .breadcrumbs h1 {
     word-break: break-all;
+    border: none;
 }
 
 #back_title {
@@ -484,15 +486,15 @@ textarea {
     width: 100%;
 }
 
-a.not_thing {
+#not_thing {
     color: #bf4c4c;
 }
 
-a.out_link {
+#out_link {
     color: #008000;
 }
 
-a.out_link::before {
+#out_link::before {
     padding: 0px;
     background: transparent;
     color: green;
@@ -507,6 +509,8 @@ a.out_link::before {
 h1, h2, h3, h4, h5, h6 {
     margin-bottom: 10px;
     margin-top: 10px;
+    border-bottom: 1px solid #CCC;
+    padding-bottom: 5px;
 }
 
 .navbar-brand {

+ 2 - 0
views/acme/css/style.css

@@ -206,6 +206,8 @@ ul.dropdown-menu {
 .copyright {
     color: #fff;
     padding-top: 15px;
+    width: 95%;
+    margin: auto;
 }
 
 #search {

+ 26 - 35
views/acme/index.tpl → views/acme/index.html

@@ -9,8 +9,8 @@
         <script src="/views/acme/js/jquery.min.js"></script>
         <script src="/views/acme/js/bootstrap.min.js"></script>
         <link rel="stylesheet" href="/views/acme/css/font-awesome/css/font-awesome.min.css">
-        {{!imp[1][5]}}
-        {{!imp[2][3]}}
+        {{imp[1][5]|safe}}
+        {{imp[2][3]|safe}}
         <meta name="twitter:creator" content="@{{imp[1][0]}}">
         <meta name="twitter:title" content="{{imp[0]}}">
         <meta name="twitter:site" content="@{{imp[1][0]}}">
@@ -28,7 +28,7 @@
                         <span class="icon-bar"></span>
                     </button>
                     <a class="navbar-brand" href="/" style="margin-top: 30px;">
-                        {{!imp[1][4]}}
+                        {{imp[1][4]|safe}}
                     </a>
                 </div>
                 <div class="navbar-collapse collapse">
@@ -73,22 +73,18 @@
                         </li>       
                         <li>
                             <a href="/user">
-                                % if(imp[2][2] == 1):
+                                {% if imp[2][2] == 1 %}
                                     <i class="fa fa-user" aria-hidden="true"></i>
-                                % elif(imp[2][2] == 0):
+                                {% elif imp[2][2] == 0 %}
                                     <i class="fa fa-user-times" aria-hidden="true"></i>
-                                % else:
+                                {% else %}
                                     <i class="fa fa-user-secret" aria-hidden="true"></i>
-                                % end
-
-                                % if(imp[2][4] != ''):
-                                    % import hashlib
-                                    % md5_email = hashlib.md5(imp[2][4].encode()).hexdigest()
-                                    
-                                    <img src="http://www.gravatar.com/avatar/{{md5_email}}?s=30">
-                                % else:
+                                {% endif %}
+                                {% if imp[2][4] != '' %}
+                                    <img src="https://www.gravatar.com/avatar/{{imp[2][4]|md5_replace}}?s=30">
+                                {% else %}
                                     사용자
-                                % end
+                                {% endif %}
                             </a>
                         </li>  
                     </ul>
@@ -102,33 +98,28 @@
                         <div class="col-lg-4 col-sm-4">
                             <h1>
                                 {{imp[0]}}
-                                % if(imp[3][0] != 0):
+                                {% if imp[3][0] != 0 %}
                                     <sub>{{imp[3][0]}}</sub>
-                                % end
+                                {% endif %}
                             </h1>
                         </div>
                         <div class="col-lg-8 col-sm-8">
                             <ol class="breadcrumb pull-right">   
                                 <li style="margin: 0;">
-                                    % if(menu != 0):
-                                        % i = 1
-                                        % for sub_d in menu:
-                                            % if(sub_d[1] == 1):
+                                    {% if menu != 0 %}
+                                        {% for sub_d in menu %}
+                                            {% if sub_d[1] == 1 %}
                                                 <a class="menu-item" href="/{{sub_d[0]}}" id="open">토론</a>
-                                            % elif(sub_d[1] == 0):
+                                            {% elif sub_d[1] == 0 %}
                                                 <a class="menu-item" href="/{{sub_d[0]}}">토론</a>
-                                            % else:
+                                            {% else %}
                                                 <a class="menu-item" href="/{{sub_d[0]}}">{{sub_d[1]}}</a>
-                                            % end
-                                            % try:
-                                                % d = menu[i]
+                                            {% endif %}
+                                            {% if menu[loop.index] %}
-                                            % except:
-                                                % break
-                                            % end
-                                            % i += 1
-                                        % end
-                                    % end
+                                            {% endif %}
+                                        {% endfor %}
+                                    {% endif %}
                                 </li>
                             </ol>
                         </div>
@@ -138,7 +129,7 @@
             <div class="container">
                 <div class="row">
                     <div class="col-md-10 col-md-offset-1 mar-b-30">
-                        {{!data}}
+                        {{data|safe}}
                     </div>
                 </div>
             </div>
@@ -158,7 +149,7 @@
             <div class="container">
                 <div class="row">
                     <div class="copyright">
-                        {{!imp[1][1]}}
+                        {{imp[1][1]|safe}}
                         <span id="left_end" class="pull-right">
                             <a href="https://github.com/2DU/openNAMU">
                                 <img src="/views/acme/img/on2.png" alt="opennamu" style="width: 100px;">
@@ -170,4 +161,4 @@
             </div>
         </footer>
     </body>
-</html>
+</html>

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است