Explorar el Código

Merge pull request #388 from 2DU/parser

Parser
ect (or 2du) hace 8 años
padre
commit
0ccfbd1b5d
Se han modificado 17 ficheros con 679 adiciones y 1119 borrados
  1. 72 129
      app.py
  2. 4 4
      func.py
  3. 16 69
      mark.py
  4. 0 14
      set_mark/blockquote.py
  5. 0 75
      set_mark/footnote.py
  6. 0 38
      set_mark/html_pas.py
  7. 0 70
      set_mark/include_pas.py
  8. 0 46
      set_mark/indent.py
  9. 0 181
      set_mark/link.py
  10. 0 114
      set_mark/macro.py
  11. 0 24
      set_mark/redirect_pas.py
  12. 539 6
      set_mark/start.py
  13. 0 246
      set_mark/table.py
  14. 0 19
      set_mark/text_help.py
  15. 0 82
      set_mark/toc_pas.py
  16. 43 0
      set_mark/tool.py
  17. 5 2
      version.md

+ 72 - 129
app.py

@@ -1,4 +1,5 @@
 from flask import Flask, request, send_from_directory
+from flask_compress import Compress
 from flask_reggie import Reggie
 
 from tornado.wsgi import WSGIContainer
@@ -16,13 +17,14 @@ import sys
 logging.basicConfig(level = logging.ERROR)
 app = Flask(__name__)
 Reggie(app)
+compress = Compress()
+compress.init_app(app)
 
-r_ver = 'v2.6.5 Beta'
+r_ver = 'v3.0.0 Beta'
 print('Version : ' + r_ver)
 
 from func import *
-from set_mark.mid_pas import mid_pas
-from set_mark.macro import savemark
+from set_mark.tool import savemark
 
 # set.json 설정 확인
 try:
@@ -832,8 +834,7 @@ def indexing():
             except:
                 pass
     else:
-        curs.execute("select name from sqlite_master where type in ('table', 'view') and name not like " + \
-                    "'sqlite_%' union all select name from sqlite_temp_master where type in ('table', 'view') order by 1;")
+        curs.execute("select name from sqlite_master where type in ('table', 'view') and name not like 'sqlite_%' union all select name from sqlite_temp_master where type in ('table', 'view') order by 1;")
         data = curs.fetchall()
         
         for table in data:            
@@ -879,8 +880,7 @@ def xref(name = None):
         
     div = '<ul>'
     
-    curs.execute("select link, type from back where title = ? and not type = 'cat' and not type = 'no' order by link asc limit ?, '50'", \
-                [name, str(sql_num)])
+    curs.execute("select link, type from back where title = ? and not type = 'cat' and not type = 'no' order by link asc limit ?, '50'", [name, str(sql_num)])
     data_list = curs.fetchall()
     for data in data_list:
         div += '<li><a href="/w/' + url_pas(data[0]) + '">' + data[0] + '</a>'
@@ -947,8 +947,7 @@ def recent_discuss(tools = 'normal'):
             div += '<a href="/recent_discuss">(열림)</a>'
             m_sub = ' (닫힘)'
 
-        div +=  '<hr><table style="width: 100%; text-align: center;"><tbody><tr> \
-                <td style="width: 50%;">토론명</td><td style="width: 50%;">시간</td></tr>'
+        div +=  '<hr><table style="width: 100%; text-align: center;"><tbody><tr><td style="width: 50%;">토론명</td><td style="width: 50%;">시간</td></tr>'
     else:
         return redirect('/')
     
@@ -968,8 +967,7 @@ def recent_discuss(tools = 'normal'):
                 close = 1
 
         if close == 0:
-            div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + \
-                    title + '</a> (' + sub + ')</td><td>' + data[2] + '</td></tr>'
+            div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[1]) + '">' + title + '</a> (' + sub + ')</td><td>' + data[2] + '</td></tr>'
     else:
         div += '</tbody></table>'
             
@@ -989,15 +987,12 @@ def block_log(name = None, tool = None, tool2 = None):
     else:
         sql_num = 0
     
-    div = '<table style="width: 100%; text-align: center;"><tbody><tr><td style="width: 33.3%;">차단자</td>' + \
-        '<td style="width: 33.3%;">관리자</td><td style="width: 33.3%;">기간</td></tr>'
+    div = '<table style="width: 100%; text-align: center;"><tbody><tr><td style="width: 33.3%;">차단자</td><td style="width: 33.3%;">관리자</td><td style="width: 33.3%;">기간</td></tr>'
     data_list = ''
     
     if not name:
         if not tool2:
-            div = '<a href="/manager/11">(차단자)</a> <a href="/manager/12">(관리자)</a><hr><a href="/block_log/ip">(아이피)</a>' + \
-                ' <a href="/block_log/user">(가입자)</a> <a href="/block_log/never_end">(영구)</a> <a href="/block_log/can_end">(기간)</a>' + \
-                ' <a href="/block_log/end">(해제)</a> <a href="/block_log/now">(현재)</a><hr>' + div
+            div = '<a href="/manager/11">(차단자)</a> <a href="/manager/12">(관리자)</a><hr><a href="/block_log/ip">(아이피)</a> <a href="/block_log/user">(가입자)</a> <a href="/block_log/never_end">(영구)</a> <a href="/block_log/can_end">(기간)</a> <a href="/block_log/end">(해제)</a> <a href="/block_log/now">(현재)</a><hr>' + div
             sub = 0
             menu = [['other', '기타']]
 
@@ -1008,18 +1003,15 @@ def block_log(name = None, tool = None, tool2 = None):
             if tool2 == 'ip':
                 sub = ' (아이피)'
 
-                curs.execute("select why, block, blocker, end, today from rb where (block like ? or block like ?) order by today desc limit ?, '50'", \
-                            ['%.%', '%:%', str(sql_num)])
+                curs.execute("select why, block, blocker, end, today from rb where (block like ? or block like ?) order by today desc limit ?, '50'", ['%.%', '%:%', str(sql_num)])
             elif tool2 == 'user':
                 sub = ' (가입자)'
 
-                curs.execute("select why, block, blocker, end, today from rb where not (block like ? or block like ?) order by today desc limit ?, '50'", \
-                            ['%.%', '%:%', str(sql_num)])
+                curs.execute("select why, block, blocker, end, today from rb where not (block like ? or block like ?) order by today desc limit ?, '50'", ['%.%', '%:%', str(sql_num)])
             elif tool2 == 'never_end':
                 sub = '(영구)'
 
-                curs.execute("select why, block, blocker, end, today from rb where not end like ? and not end like ? order by today desc limit ?, '50'", \
-                            ['%:%', '%해제%', str(sql_num)])
+                curs.execute("select why, block, blocker, end, today from rb where not end like ? and not end like ? order by today desc limit ?, '50'", ['%:%', '%해제%', str(sql_num)])
             elif tool2 == 'end':
                 sub = '(해제)'
 
@@ -1120,9 +1112,7 @@ def deep_search(name = None):
     else:
         div = '<ul><li>문서가 없습니다. <a class="not_thing" href="/w/' + url_pas(name) + '">바로가기</a></li></ul><hr><ul>'
 
-    curs.execute("select distinct title, case when title like ? then '제목' else '내용' " + \
-                "end from data where title like ? or data like ? order by case when title like ? " + \
-                "then 1 else 2 end limit ?, '50'", ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', str(sql_num)])
+    curs.execute("select distinct title, case when title like ? then '제목' else '내용' end from data where title like ? or data like ? order by case when title like ? then 1 else 2 end limit ?, '50'", ['%' + name + '%', '%' + name + '%', '%' + name + '%', '%' + name + '%', str(sql_num)])
     all_list = curs.fetchall()
     if all_list:
         test = all_list[0][1]
@@ -1416,8 +1406,7 @@ def edit(name = None):
                 match = re.compile(data_list[0])
                 if match.search(request.form['content']):
                     if data_list[1] == 'X':
-                        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, '')", \
-                                    [ip, '', get_time(), '도구:편집 필터', '편집 필터에 의한 차단'])
+                        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, '')", [ip, '', get_time(), '도구:편집 필터', '편집 필터에 의한 차단'])
                         curs.execute("insert into ban (block, end, why, band, login) values (?, '', ?, '', '')", [ip, '편집 필터에 의한 차단'])
                     elif data_list[1] != '':
                         match = re.search("^([^ ]+) ([^:]+):([^:]+)$", data_list[1])
@@ -1464,8 +1453,7 @@ def edit(name = None):
 
                         end = str(year) + '-' + time_list[0] + '-' + time_list[1] + ' ' + time_list[2] + ':' + time_list[3] + ':' + time_data[5]
 
-                        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, '')", \
-                                    [ip, end, get_time(), '도구:편집 필터', '편집 필터에 의한 차단'])
+                        curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, '')", [ip, end, get_time(), '도구:편집 필터', '편집 필터에 의한 차단'])
                         curs.execute("insert into ban (block, end, why, band, login) values (?, ?, ?, '', '')", [ip, end, '편집 필터에 의한 차단'])
                     
                     conn.commit()
@@ -1493,7 +1481,10 @@ def edit(name = None):
 
             leng = leng_check(len(request.form['otent']), len(content))
             if request.args.get('section', None):
-                content = old[0][0].replace(request.form['otent'], content)      
+                if not re.search('\r\n$', content):
+                    content = old[0][0].replace(request.form['otent'], content + '\r\n')
+                else:
+                    content = old[0][0].replace(request.form['otent'], content)
                 
             curs.execute("update data set data = ? where title = ?", [content, name])
         else:
@@ -1502,10 +1493,9 @@ def edit(name = None):
 
         curs.execute("select user from scan where title = ?", [name])
         for user_data in curs.fetchall():
-            curs.execute("insert into alarm (name, data, date) values (?, ?, ?)", \
-                        [ip, ip + '님이 <a href="/w/' + url_pas(name) + '">' + name + '</a> 문서를 편집 했습니다.', today])
+            curs.execute("insert into alarm (name, data, date) values (?, ?, ?)", [ip, ip + '님이 <a href="/w/' + url_pas(name) + '">' + name + '</a> 문서를 편집 했습니다.', today])
 
-        history_plus(conn, name, content, today, ip, send_p(request.form['send']), leng)
+        history_plus(conn, name, content, today, ip, send_parser(request.form['send']), leng)
         curs.execute("delete from back where link = ?", [name])
         curs.execute("delete from back where title = ? and type = 'no'", [name])
         namumark(conn, name, content, 1, 0, 0)
@@ -1517,31 +1507,10 @@ def edit(name = None):
         new = curs.fetchall()
         if new:
             if request.args.get('section', None):
-                i = 0
-                j = 0
-                
-                data = new[0][0] + '\r\n'
-                while 1:
-                    m = re.search("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})" + \
-                                "\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", data)
-                    if m:
-                        if i == int(request.args.get('section', 0)) - 1:
-                            g = m.groups()
-                            data = re.sub("\r\n$", "", g[0])
-                            
-                            break
-                        else:
-                            data = re.sub("((?:={1,6})\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n(?:(?:(?:(?!(?:={1,6})" + \
-                                        "\s?(?:[^=]*)\s?(?:={1,6})(?:\s+)?\n).)*)(?:\n)?)+)", "", data, 1)
-                            
-                            i += 1
-                    else:
-                        j = 1
-                        
-                        break
-                        
-                if j == 0:
-                    data = re.sub("\r\n$", "", data)
+                test_data = '\r\n' + new[0][0] + '\r\n'   
+
+                section_data = re.findall('(\r\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\r\n(?:(?:(?:(?!\r\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\r\n).)|\n)*))', test_data)
+                data = section_data[int(request.args.get('section', None)) - 1][0]
             else:
                 data = new[0][0]
         else:
@@ -1592,9 +1561,12 @@ def preview(name = None):
     if can == 1:
         return re_error(conn, '/ban')
          
-    newdata = request.form['content']
-    newdata = re.sub('^#(?:redirect|넘겨주기) (?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
-    enddata = namumark(conn, name, newdata, 0, 0, 1)
+    new_data = request.form['content']
+    new_data = re.sub('\r\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\r\n).)+)\r\n', ' * [[\g<in>]] 문서로 넘겨주기', '\r\n' + new_data + '\r\n')
+    new_data = re.sub('^\r\n', '', new_data)
+    new_data = re.sub('\r\n$', '', new_data)
+    
+    end_data = namumark(conn, name, new_data, 0, 0, 1)
 
     if request.args.get('section', None):
         action = '?section=' + request.args.get('section', None)
@@ -1610,7 +1582,7 @@ def preview(name = None):
                     ' + captcha_get(conn) + ' \
                     <button id="save" type="submit">저장</button> \
                     <button id="preview" type="submit" formaction="/preview/' + url_pas(name) + action + '">미리보기</button> \
-                </form><hr>' + enddata,
+                </form><hr>' + end_data,
         menu = [['w/' + url_pas(name), '문서']]
     ))
         
@@ -1665,8 +1637,7 @@ def delete(name = None):
 def move_data(name = None):    
     data = '<ul>'
 
-    curs.execute("select send, date, ip from history where send like ? or send like ? order by date desc", \
-                ['%<a href="/w/' + url_pas(name) + '">' + name + '</a> 이동)%', '%(<a href="/w/' + url_pas(name) + '">' + name + '</a>%'])
+    curs.execute("select send, date, ip from history where send like ? or send like ? order by date desc", ['%<a href="/w/' + url_pas(name) + '">' + name + '</a> 이동)%', '%(<a href="/w/' + url_pas(name) + '">' + name + '</a>%'])
     for for_data in curs.fetchall():
         match = re.findall('<a href="\/w\/(?:(?:(?!">).)+)">((?:(?!<\/a>).)+)<\/a>', for_data[0])
         send = re.sub('\([^\)]+\)$', '', for_data[0])
@@ -1716,8 +1687,7 @@ def move(name = None):
         else:
             d = ''
             
-        history_plus(conn, name, d, today, ip, request.form['send'] + ' (<a href="/w/' + url_pas(name) + '">' + name + \
-                    '</a> - <a href="/w/' + url_pas(request.form['title']) + '">' + request.form['title'] + '</a> 이동)', leng)
+        history_plus(conn, name, d, today, ip, request.form['send'] + ' (<a href="/w/' + url_pas(name) + '">' + name + '</a> - <a href="/w/' + url_pas(request.form['title']) + '">' + request.form['title'] + '</a> 이동)', leng)
 
         curs.execute("select title, link from back where title = ? and not type = 'cat' and not type = 'no'", [name])
         for data in curs.fetchall():
@@ -1955,22 +1925,18 @@ def topic_stop(name = None, sub = None, tool = None):
         if tool == 'agree':
             curs.execute("select title from agreedis where title = ? and sub = ?", [name, sub])
             if curs.fetchall():
-                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 결렬', ?, ?, '', '1')", \
-                            [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
+                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 결렬', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
                 curs.execute("delete from agreedis where title = ? and sub = ?", [name, sub])
             else:
-                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 완료', ?, ?, '', '1')", \
-                            [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
+                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, '합의 완료', ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, time, ip])
                 curs.execute("insert into agreedis (title, sub) values (?, ?)", [name, sub])
         else:
             curs.execute("select title from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[0]])
             if curs.fetchall():
-                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", \
-                            [str(int(topic_check[0][0]) + 1), name, sub, set_list[3], time, ip])
+                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, set_list[3], time, ip])
                 curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[0]])
             else:
-                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", \
-                            [str(int(topic_check[0][0]) + 1), name, sub, set_list[2], time, ip])
+                curs.execute("insert into topic (id, title, sub, data, date, ip, block, top) values (?, ?, ?, ?, ?, ?, '', '1')", [str(int(topic_check[0][0]) + 1), name, sub, set_list[2], time, ip])
                 curs.execute("insert into stop (title, sub, close) values (?, ?, ?)", [name, sub, set_list[0]])
                 curs.execute("delete from stop where title = ? and sub = ? and close = ?", [name, sub, set_list[1]])
         
@@ -2175,9 +2141,7 @@ def topic(name = None, sub = None):
             number += 1
 
         if ban != 1 or admin == 1:
-            data += '<a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\') ?  ' + \
-                    'location.reload(true) : location.href = \'#reload\'"><i aria-hidden="true" class="fa fa-refresh"></i></a>' + \
-                    '<form style="' + display + '" method="post"><br><textarea style="height: 100px;" name="content"></textarea><hr>' + captcha_get(conn)
+            data += '<a id="reload" href="javascript:void(0);" onclick="location.href.endsWith(\'#reload\')? location.reload(true):location.href=\'#reload\'"><i aria-hidden="true" class="fa fa-refresh"></i></a><form style="' + display + '" method="post"><br><textarea style="height: 100px;" name="content"></textarea><hr>' + captcha_get(conn)
             
             if display == '':
                 data += ip_warring(conn)
@@ -2222,9 +2186,7 @@ def close_topic_list(name = None, tool = None):
             curs.execute("select sub from rd where title = ? order by date desc", [name])
             sub = '토론 목록'
             menu = [['w/' + url_pas(name), '문서']]
-            plus =  '<a href="/topic/' + url_pas(name) + '/close">(닫힘)</a> <a href="/topic/' + url_pas(name) + '/agree">(합의)</a><hr> \
-                    <input placeholder="토론명" class="form-control" name="topic" type="text"><hr> \
-                    <button type="submit">만들기</button>'
+            plus =  '<a href="/topic/' + url_pas(name) + '/close">(닫힘)</a> <a href="/topic/' + url_pas(name) + '/agree">(합의)</a><hr><input placeholder="토론명" class="form-control" name="topic" type="text"><hr><button type="submit">만들기</button>'
 
         for data in curs.fetchall():
             curs.execute("select data, date, ip, block from topic where title = ? and sub = ? and id = '1'", [name, data[0]])
@@ -2237,8 +2199,7 @@ def close_topic_list(name = None, tool = None):
                         it_p = 1
                 
                 if it_p != 1:
-                    div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + data[0] + \
-                            '</a></h2><hr id="under_bar" style="margin-top: -5px;">'
+                    div += '<h2><a href="/topic/' + url_pas(name) + '/sub/' + url_pas(data[0]) + '">' + data[0] + '</a></h2><hr id="under_bar" style="margin-top: -5px; margin-bottom: 10px;">'
 
         if div == '':
             plus = re.sub('^<br>', '', plus)
@@ -2461,11 +2422,9 @@ def register():
         curs.execute("select id from user limit 1")
         user_ex = curs.fetchall()
         if not user_ex:
-            curs.execute("insert into user (id, pw, acl, date, email) values (?, ?, 'owner', ?, ?)", \
-                        [request.form['id'], hashed.decode(), get_time(), request.form.get('email', '')])
+            curs.execute("insert into user (id, pw, acl, date, email) values (?, ?, 'owner', ?, ?)", [request.form['id'], hashed.decode(), get_time(), request.form.get('email', '')])
         else:
-            curs.execute("insert into user (id, pw, acl, date, email) values (?, ?, 'user', ?, ?)", \
-                        [request.form['id'], hashed.decode(), get_time(), request.form.get('email', '')])
+            curs.execute("insert into user (id, pw, acl, date, email) values (?, ?, 'user', ?, ?)", [request.form['id'], hashed.decode(), get_time(), request.form.get('email', '')])
         conn.commit()
         
         return redirect('/login')
@@ -2541,10 +2500,8 @@ def user_ban(name = None):
             else:
                 login = ''
 
-            curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)", \
-                        [name, end, time, ip, request.form['why'], band_d])
-            curs.execute("insert into ban (block, end, why, band, login) values (?, ?, ?, ?, ?)", \
-                        [name, end, request.form['why'], band_d, login])
+            curs.execute("insert into rb (block, end, today, blocker, why, band) values (?, ?, ?, ?, ?, ?)", [name, end, time, ip, request.form['why'], band_d])
+            curs.execute("insert into ban (block, end, why, band, login) values (?, ?, ?, ?, ?)", [name, end, request.form['why'], band_d, login])
 
         conn.commit()
         return redirect('/ban/' + url_pas(name))            
@@ -2892,7 +2849,7 @@ def read_view(name = None):
                     curs.execute("select data from data where title = ?", [data[0]])
                     db_data = curs.fetchall()
                     if db_data:
-                        cat_data = re.sub("\[\[(분류:(?:(?:(?!\]\]|#include).)+))\]\]", "", mid_pas(db_data[0][0], 0, 1, 0, 0)[0])
+                        # cat_data = re.sub("\[\[(분류:(?:(?:(?!\]\]|#include).)+))\]\]", "", mid_pas(db_data[0][0], 0, 1, 0, 0)[0])
                         if re.search('\[\[' + name + '|include]]', cat_data):
                             div += ' * [[' + data[0] + ']]\r\n * [[wiki:xref/' + url_pas(data[0]) + '|' + data[0] + ']] (역링크)\r\n'
                         else:
@@ -2913,11 +2870,11 @@ def read_view(name = None):
         curs.execute("select title, data from data where title = ?", [name])
     data = curs.fetchall()
     if data:
-        elsedata = data[0][1]
+        else_data = data[0][1]
     else:
         data_none = 1
         response.status = 404
-        elsedata = ''
+        else_data = ''
 
     if not num:
         curs.execute("select dec from acl where title = ?", [name])
@@ -2960,25 +2917,23 @@ def read_view(name = None):
                 acl += ' (가입자)'
             
     if request.args.get('froms', None):
-        elsedata = re.sub("^#(?:redirect|넘겨주기) (?P<in>[^\n]*)", " * [[\g<in>]] 문서로 넘겨주기", elsedata)
+        else_data = re.sub('\r\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\r\n).)+)\r\n', ' * [[\g<in>]] 문서로 넘겨주기', '\r\n' + else_data + '\r\n')
+        else_data = re.sub('^\r\n', '', else_data)
+        else_data = re.sub('\r\n$', '', else_data)
             
-    enddata = namumark(conn, name, elsedata, 0, 0, 1)
+    end_data = namumark(conn, name, else_data, 0, 0, 1)
 
     if data_none == 1:
-        menu = [['edit/' + url_pas(name), '생성'], ['topic/' + url_pas(name), topic], \
-                ['history/' + url_pas(name), '역사'], ['move/' + url_pas(name), '이동'], ['xref/' + url_pas(name), '역링크']]
+        menu = [['edit/' + url_pas(name), '생성'], ['topic/' + url_pas(name), topic], ['history/' + url_pas(name), '역사'], ['move/' + url_pas(name), '이동'], ['xref/' + url_pas(name), '역링크']]
     else:
-        menu = [['edit/' + url_pas(name), '수정'], ['topic/' + url_pas(name), topic], \
-                ['history/' + url_pas(name), '역사'], ['delete/' + url_pas(name), '삭제'], \
-                ['move/' + url_pas(name), '이동'], ['raw/' + url_pas(name), '원본'], ['xref/' + url_pas(name), '역링크']]
+        menu = [['edit/' + url_pas(name), '수정'], ['topic/' + url_pas(name), topic], ['history/' + url_pas(name), '역사'], ['delete/' + url_pas(name), '삭제'], ['move/' + url_pas(name), '이동'], ['raw/' + url_pas(name), '원본'], ['xref/' + url_pas(name), '역링크']]
         
     if admin_memu == 1:
         menu += [['acl/' + url_pas(name), 'ACL']]
 
     if request.args.get('froms', None):
         menu += [['w/' + url_pas(name), '넘기기']]
-        enddata = '<ul id="redirect"><li><a href="/w/' + url_pas(request.args.get('froms', None)) + \
-                    '?froms=' + url_pas(name) + '">' + request.args.get('froms', None) + '</a>에서 넘어 왔습니다.</li></ul><br>' + enddata
+        end_data = '<ul id="redirect"><li><a href="/w/' + url_pas(request.args.get('froms', None)) + '?froms=' + url_pas(name) + '">' + request.args.get('froms', None) + '</a>에서 넘어 왔습니다.</li></ul><br>' + end_data
 
     if uppage != 0:
         menu += [['w/' + url_pas(uppage), '상위']]
@@ -2999,10 +2954,10 @@ def read_view(name = None):
         else:
             r_date = 0
 
-    if div != '' and enddata != '':
-        div = enddata + '<br>' + namumark(conn, name, div, 0, 0, 0)
+    if div != '' and end_data != '':
+        div = end_data + '<br>' + namumark(conn, name, div, 0, 0, 0)
     else:
-        div = enddata + namumark(conn, name, div, 0, 0, 0)
+        div = end_data + namumark(conn, name, div, 0, 0, 0)
 
     return html_minify(template('index', 
         imp = [name, wiki_set(conn, 1), custom(conn), other2([sub + acl, r_date])],
@@ -3039,8 +2994,7 @@ def user_topic_list(name = None):
             
         ip = ip_pas(conn, data[3])
             
-        div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[2]) + '#' + data[1] + '">' + \
-                title + '#' + data[1] + '</a> (' + sub + ')</td>'
+        div += '<tr><td><a href="/topic/' + url_pas(data[0]) + '/sub/' + url_pas(data[2]) + '#' + data[1] + '">' + title + '#' + data[1] + '</a> (' + sub + ')</td>'
         div += '<td>' + ip + ban +  '</td><td>' + data[4] + '</td></tr>'
 
     div += '</tbody></table>'
@@ -3083,8 +3037,7 @@ def recent_changes(name = None, tool = 'record'):
             if tool == 'history':
                 div += '<td style="width: 33.3%;">판</td><td style="width: 33.3%;">편집자</td><td style="width: 33.3%;">시간</td></tr>'
 
-                curs.execute("select id, title, date, ip, send, leng from history where title = ? order by id + 0 desc limit ?, '50'", \
-                            [name, str(sql_num)])
+                curs.execute("select id, title, date, ip, send, leng from history where title = ? order by id + 0 desc limit ?, '50'", [name, str(sql_num)])
             else:
                 div += '<td style="width: 33.3%;">문서명</td><td style="width: 33.3%;">편집자</td><td style="width: 33.3%;">시간</td></tr>'
 
@@ -3093,8 +3046,7 @@ def recent_changes(name = None, tool = 'record'):
                     div = '<a href="/record/' + url_pas(name) + '?what=move">(이동)</a> ' + div
                     div = '<a href="/record/' + url_pas(name) + '?what=delete">(삭제)</a> ' + div
                 
-                    curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, '50'", \
-                                [name, str(sql_num)])
+                    curs.execute("select id, title, date, ip, send, leng from history where ip = ? order by date desc limit ?, '50'", [name, str(sql_num)])
                 else:
                     if what == 'delete':
                         sql = '%(삭제)'
@@ -3105,8 +3057,7 @@ def recent_changes(name = None, tool = 'record'):
                     else:
                         return redirect('/')
 
-                    curs.execute("select id, title, date, ip, send, leng from history where ip = ? and send like ? order by date desc limit ?, '50'", \
-                                [name, sql, str(sql_num)])
+                    curs.execute("select id, title, date, ip, send, leng from history where ip = ? and send like ? order by date desc limit ?, '50'", [name, sql, str(sql_num)])
         else:
             div += '<td style="width: 33.3%;">문서명</td><td style="width: 33.3%;">편집자</td><td style="width: 33.3%;">시간</td></tr>'
 
@@ -3155,8 +3106,7 @@ def recent_changes(name = None, tool = 'record'):
             if (int(data[0]) - 1) == 0:
                 revert = ''
             else:
-                revert = '<a href="/diff/' + url_pas(data[1]) + '?first=' + str(int(data[0]) - 1) + '&second=' + data[0] + \
-                        '">(비교)</a> <a href="/revert/' + url_pas(data[1]) + '?num=' + str(int(data[0]) - 1) + '">(되돌리기)</a>'
+                revert = '<a href="/diff/' + url_pas(data[1]) + '?first=' + str(int(data[0]) - 1) + '&second=' + data[0] + '">(비교)</a> <a href="/revert/' + url_pas(data[1]) + '?num=' + str(int(data[0]) - 1) + '">(되돌리기)</a>'
             
             style = ['', '']
             date = data[2]
@@ -3189,11 +3139,9 @@ def recent_changes(name = None, tool = 'record'):
                 style[1] = 'background: gainsboro;'
 
             if tool == 'history':
-                title = '<a href="/w/' + url_pas(name) + '?num=' + data[0] + '">' + data[0] + '판</a> <a href="/raw/' + \
-                        url_pas(name) + '?num=' + data[0] + '">(원본)</a> '
+                title = '<a href="/w/' + url_pas(name) + '?num=' + data[0] + '">' + data[0] + '판</a> <a href="/raw/' + url_pas(name) + '?num=' + data[0] + '">(원본)</a> '
             else:
-                title = '<a href="/w/' + url_pas(data[1]) + '">' + html.escape(data[1]) + '</a> <a href="/history/' + \
-                        url_pas(data[1]) + '">(' + data[0] + '판)</a> '
+                title = '<a href="/w/' + url_pas(data[1]) + '">' + html.escape(data[1]) + '</a> <a href="/history/' + url_pas(data[1]) + '">(' + data[0] + '판)</a> '
                     
             div += '<tr style="' + style[0] + '"><td>' + title + revert + ' ' + leng + '</td>'
             div += '<td>' + ip + ban + hidden + '</td><td>' + date + '</td></tr><tr style="' + style[1] + '"><td colspan="3">' + send + '</td></tr>'
@@ -3203,8 +3151,7 @@ def recent_changes(name = None, tool = 'record'):
 
         if name:
             if tool == 'history':
-                div = '<form method="post"><select name="a">' + select + '</select> <select name="b">' + select + \
-                        '</select> <button type="submit">비교</button></form><hr>' + div
+                div = '<form method="post"><select name="a">' + select + '</select> <select name="b">' + select + '</select> <button type="submit">비교</button></form><hr>' + div
                 title = name
                 sub += ' (역사)'
                 menu = [['w/' + url_pas(name), '문서'], ['move_data/' + url_pas(name), '이동 기록']]
@@ -3304,11 +3251,9 @@ def upload():
         if(exist): 
             curs.execute("delete from data where title = ?", ['파일:' + name])
         
-        curs.execute("insert into data (title, data) values (?, ?)", \
-                    ['파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice])
+        curs.execute("insert into data (title, data) values (?, ?)", ['파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice])
         curs.execute("insert into acl (title, dec, dis, why) values (?, 'admin', '', '')", ['파일:' + name])
-        history_plus(conn, '파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice, \
-                    get_time(), ip, '(파일 올림)', '0')
+        history_plus(conn, '파일:' + name, '[[파일:' + name + ']][br][br]{{{[[파일:' + name + ']]}}}[br][br]' + lice, get_time(), ip, '(파일 올림)', '0')
         conn.commit()
         
         return redirect('/w/파일:' + name)            
@@ -3411,8 +3356,7 @@ def watch_list():
     curs.execute("select title from scan where user = ?", [ip])
     data = curs.fetchall()
     for data_list in data:
-        div += '<li><a href="/w/' + url_pas(data_list[0]) + '">' + data_list[0] + '</a> <a href="/watch_list/' + \
-                url_pas(data_list[0]) + '">(삭제)</a></li>'
+        div += '<li><a href="/w/' + url_pas(data_list[0]) + '">' + data_list[0] + '</a> <a href="/watch_list/' + url_pas(data_list[0]) + '">(삭제)</a></li>'
 
     if data:
         div = '<ul>' + div + '</ul><hr>'
@@ -3531,8 +3475,7 @@ def count_edit(name = None):
 
     return html_minify(template('index', 
         imp = ['활동 횟수', wiki_set(conn, 1), custom(conn), other2([0, 0])],
-        data = namumark(conn, "", "[목차(없음)]\r\n== " + that + " ==\r\n||<:> 편집 횟수 ||<:> " + str(data) + \
-                        "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
+        data = namumark(conn, "", "[목차(없음)]\r\n== " + that + " ==\r\n||<:> 편집 횟수 ||<:> " + str(data) + "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
         menu = [['user', '사용자'], ['record/' + url_pas(that), '편집 기록'], ['topic_record/' + url_pas(that), '토론 기록']]
     ))
         

+ 4 - 4
func.py

@@ -13,11 +13,11 @@ 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()

+ 16 - 69
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,18 +7,15 @@ from urllib import parse
 import time
 import threading
 
-def send_p(d):
-    d = html.escape(d)
+def send_parser(data):
+    data = html.escape(data)
 
-    js_p = re.compile('javascript:', re.I)
-    d = js_p.sub('', d)
+    javascript = re.compile('javascript:', re.I)
+    data = javascript.sub('', data)
 
-    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')
+    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()
@@ -40,52 +24,15 @@ def plusing(conn, name, link, 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]
+def namumark(conn, title, data, num, in_c, toc_y):
+    data = start(conn, data, title)
     
-    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>'
-    
-    if num == 1:        
-        for d4 in backlink:
-            t = threading.Thread(target = plusing, args = [conn, d4[0], d4[1], d4[2]])
-            t.start()
-            t.join()
-
-        conn.commit()
+    # if num == 1:        
+    #     for d4 in backlink:
+    #         t = threading.Thread(target = plusing, args = [conn, d4[0], d4[1], d4[2]])
+    #         t.start()
+    #         t.join()
+    #
+    #     conn.commit()
         
     return data

+ 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 - 75
set_mark/footnote.py

@@ -1,75 +0,0 @@
-import re
-
-def footnote(data, fol_num):
-    a = 1
-    tou = "<hr style='margin-top: 30px;' id='footnote'><div><br>"
-    namu = []
-    div = ''
-
-    data = re.sub("\[각주\](?:(?:<br>| |\r|\n)+)?$", "", data)
-
-    pop_re = re.compile('(?:\[\*([^\s]*)(?:\s((?:(?!\[|\]).)*))?\]|(\[각주\]))')
-    while 1:
-        b = pop_re.search(data)
-        if b:
-            results = b.groups()
-            if not results[2]:
-                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>" + 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>" + 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>' + div
-                    a += 1
-
-                fol_num += 2
-            else:
-                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 += 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('#no-br#<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 - 46
set_mark/indent.py

@@ -1,46 +0,0 @@
-import re
-
-def indent(data):
-    while 1:
-        m = re.search("(\n(?:(?:( *)\* ?(?:((?!\n|\|\|).)*))\n?)+)", data)
-        if m:
-            end = m.groups()[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)
-
-            if re.search(' <\/li>$', end):
-                test = ' '
-            else:
-                test = ''
-
-            data = re.sub("(\n(?:(?:( *)\* ?(?:((?!\n|\|\|).)*))\n?)+)", '<ul style="margin-top: 10px; margin-bottom: 10px;" id="list">' + end + '</ul>' + test, 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 - 181
set_mark/link.py

@@ -1,181 +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;', '"')
-                    a = a.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 - 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]

+ 539 - 6
set_mark/start.py

@@ -1,10 +1,543 @@
+from . import tool
+
 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'
-    data = re.sub('\n \|\|', '\n||', data)
+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("<table ?width=((?:(?!>).)*)>", data)
+    if table_width:
+        all_table += 'width: ' + table_width.groups()[0] + ';'
+    
+    table_height = re.search("<table ?height=((?:(?!>).)*)>", data)
+    if table_height:
+        all_table += 'height: ' + table_height.groups()[0] + ';'
+    
+    table_align = re.search("<table ?align=((?:(?!>).)*)>", 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("<table ?textalign=((?:(?!>).)*)>", 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_t_a = re.search("<row ?textalign=((?:(?!>).)*)>", data)
+    if row_t_a:
+        if row_t_a.groups()[0] == 'right':
+            row_style += 'text-align: right;'
+        elif row_t_a.groups()[0] == 'center':
+            row_style += 'text-align: center;'
+        else:
+            row_style += 'text-align: left;'
+    
+    table_cel = re.search("<-((?:(?!>).)*)>", data)
+    if table_cel:
+        cel = 'colspan="' + table_cel.groups()[0] + '"'
+    else:
+        cel = 'colspan="' + str(round(len(start_data) / 2)) + '"'   
+
+    table_row = re.search("<\|((?:(?!>).)*)>", data)
+    if table_row:
+        row = 'rowspan="' + table_row.groups()[0] + '"'
+
+    row_bgcolor = re.search("<rowbgcolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)>", data)
+    if row_bgcolor:
+        row_style += 'background: ' + row_bgcolor.groups()[0] + ';'
+        
+    table_border = re.search("<table ?bordercolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)>", data)
+    if table_border:
+        all_table += 'border: ' + table_border.groups()[0] + ' 2px solid;'
+        
+    table_bgcolor = re.search("<table ?bgcolor=(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)>", data)
+    if table_bgcolor:
+        all_table += 'background: ' + table_bgcolor.groups()[0] + ';'
+        
+    bgcolor = re.search("<(?:bgcolor=)?(#(?:[0-9a-f-A-F]{3}){1,2}|\w+)>", data)
+    if bgcolor:
+        cel_style += 'background: ' + bgcolor.groups()[0] + ';'
+        
+    cel_width = re.search("<width=((?:(?!>).)*)>", data)
+    if cel_width:
+        cel_style += 'width: ' + cel_width.groups()[0] + ';'
+
+    cel_height = re.search("<height=((?:(?!>).)*)>", data)
+    if cel_height:
+        cel_style += 'height: ' + cel_height.groups()[0] + ';'
+        
+    text_right = re.search("<\)>", data)
+    text_center = re.search("<:>", data)
+    text_left = re.search("<\(>",  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("<table ?class=((?:(?!>).)+)>", 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 = '\r\n' + data + '\r\n'
+
+    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 = 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)
+
+                data = re.sub('\[include\(((?:(?!\)\]).)+)\)\]', '\r\n<span id="include"></span>' + include_parser + '<span id="include"></span>\r\n', data, 1)
+            else:
+                data = re.sub('\[include\(((?:(?!\)\]).)+)\)\]', '[[' + include + ']]', data, 1)
+
+        else:
+            break
+
+    # 텍스트 꾸미기 문법
+    data = re.sub('\'\'\'(?P<in>(?:(?!\'\'\').)+)\'\'\'', '<b>\g<in></b>', data)
+    data = re.sub('\'\'(?P<in>(?:(?!\'\').)+)\'\'', '<i>\g<in></i>', data)
+
+    data = re.sub('~~(?P<in>(?:(?!~~).)+)~~', '<s>\g<in></s>', data)
+    data = re.sub('--(?P<in>(?:(?!~~).)+)--', '<s>\g<in></s>', data)
+
+    data = re.sub('__(?P<in>(?:(?!__).)+)__', '<u>\g<in></u>', data)
+    
+    data = re.sub('^^(?P<in>(?:(?!^^).)+)^^', '<sup>\g<in></sup>', data)
+    data = re.sub(',,(?P<in>(?:(?!,,).)+),,', '<sub>\g<in></sub>', data)
+
+    # 넘겨주기 변환
+    data = re.sub('\r\n#(?:redirect|넘겨주기) (?P<in>(?:(?!\r\n).)+)\r\n', '<meta http-equiv="refresh" content="0; url=/w/\g<in>?froms=' + tool.url_pas(title) + '">', data)
+
+    # 각주 처리
+    footnote_number = 0
+    footnote_all = '\r\n<hr><ul id="footnote_data">'
+    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 = '\r\n<hr><ul id="footnote_data">'
+            else:
+                footnote = footnote_data[1]
+                footnote_name = footnote_data[0]
+
+                footnote_number += 1
+
+                if not footnote_name:
+                    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 == '\r\n<hr><ul id="footnote_data"></ul>':
+        footnote_all = ''
+
+    data = re.sub('\r\n$', footnote_all, data)
+
+    # [목차(없음)] 처리
+    if not re.search('\[목차\(없음\)\]\r\n', data):
+        if not re.search('\[목차\]', data):
+            data = re.sub('\r\n(?P<in>={1,6}) ?(?P<out>(?:(?!=).)+) ?={1,6}\r\n', '\r\n[목차]\r\n\g<in> \g<out> \g<in>\r\n', data, 1)
+    else:
+        data = re.sub('\[목차\(없음\)\]\r\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>\r\n\r\n'
+    while 1:
+        toc = re.search('\r\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\r\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('\r\n(={1,6}) ?((?:(?!=).)+) ?={1,6}\r\n', '\r\n<h' + toc_number + '><a href="">' + 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 + '><hr id="under_bar" style="margin-top: -5px; margin-bottom: 10px;">\r\n', data, 1)
+            toc_data += '<span style="margin-left: ' + str((toc_full - toc_top_stack) * 10) + 'px"><a href="">' + all_stack + '</a> ' + toc[1] + '</span>\r\n'
+        else:
+            break
+
+    toc_data += '</div>'
+    
+    data = re.sub('\[목차\]', toc_data, data)
+
+    while 1:
+        hr = re.search('\r\n-{4,9}\r\n', data)
+        if hr:
+            data = re.sub('\r\n-{4,9}\r\n', '<hr>', data, 1)
+        else:
+            break
+
+    data += '\r\n'
+
+    # 일부 매크로 처리
+    data = tool.savemark(data)
+
+    data = re.sub("\[br\]", '\r\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
+
+        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></iframe>', data, 1)
+        else:
+            break
+
+    # 인용문 구현
+    while 1:
+        block = re.search('(\r\n(?:> ?(?:(?:(?!\r\n).)+)\r\n)+)', data)
+        if block:
+            block = block.groups()[0]
+
+            block = re.sub('^\r\n> ?', '', block)
+            block = re.sub('\r\n> ?', '\r\n', block)
+            block = re.sub('\r\n$', '', block)
+
+            data = re.sub('(\r\n(?:> ?(?:(?:(?!\r\n).)+)\r\n)+)', '<blockquote>' + block + '</blockquote>\r\n', data, 1)
+        else:
+            break
+
+    # 리스트 구현
+    while 1:
+        li = re.search('(\r\n(?:(?: *)\* ?(?:(?:(?!\r\n).)+)\r\n)+)', data)
+        if li:
+            li = li.groups()[0]
+
+            while 1:
+                sub_li = re.search('\r\n(?:( *)\* ?((?:(?!\r\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('\r\n(?:( *)\* ?((?:(?!\r\n).)+))', '<li style="margin-left: ' + str(margin) + 'px">' + sub_li[1] + '</li>', li, 1)
+                else:
+                    break
+
+            data = re.sub('(\r\n(?:(?: *)\* ?(?:(?:(?!\r\n).)+)\r\n)+)', '\r\n\r\n<ul>' + li + '</ul>\r\n', data, 1)
+        else:
+            break
+
+    # 들여쓰기 구현
+    while 1:
+        indent = re.search('\r\n( +)', data)
+        if indent:
+            indent = len(indent.groups()[0])
+            
+            # 앞에 공백 만큼 margin 먹임
+            margin = '<span style="margin-left: 20px;"></span>' * indent
+
+            data = re.sub('\r\n( +)', '\r\n' + margin, data, 1)
+        else:
+            break
+
+    # 표 처리
+    while 1:
+        table = re.search('((?:(?:(?:(?:\|\|)+(?:(?:(?!\|\|).(?:\r\n)*)+))+)\|\|(?:\r\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('^((?:\|\|)+)((?:<(?:(?:(?!>).)+)>)*)((?:(?!\|\||<\/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('^\|\|((?:<(?:(?:(?!>).)+)>)*)', '<table ' + return_table[5] + ' ' + return_table[0] + '><tbody><tr ' + return_table[1] + '><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>', table, 1)
+                else:
+                    break
+
+            table = re.sub('\|\|\r\n$', '</td></tr></tbody></table>', table)
+
+            while 1:
+                row_table = re.search('\|\|\r\n((?:\|\|)+)((?:<(?:(?:(?!>).)+)>)*)((?:(?!\|\||<\/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('\|\|\r\n((?:\|\|)+)((?:<(?:(?:(?!>).)+)>)*)', '</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('((?:\|\|)+)((?:<(?:(?:(?!>).)+)>)*)((?:(?!\|\||<\/td>).)+)', table)
+                if cel_table:
+                    cel_table = cel_table.groups()
+
+                    return_table = table_parser(cel_table[1], cel_table[2], cel_table[0], number)
+
+                    table = re.sub('((?:\|\|)+)((?:<(?:(?:(?!>).)+)>)*)', '</td><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>', table, 1)
+                else:
+                    break
+
+            data = re.sub('((?:(?:(?:(?:\|\|)+(?:(?:(?!\|\|).(?:\r\n)*)+))+)\|\|(?:\r\n)?)+)', table, data, 1)
+        else:
+            break
+
+    # 링크 관련 문법 구현
+    category = '\r\n<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]
+                    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 = ''
+
+                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 class="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_class = 'class="not_thing"'
+                else:
+                    link_class = ''
+
+                data = re.sub('\[\[((?:(?!\[\[|\]\]).)+)\]\]', '<a ' + link_class + ' href="/w/' + tool.url_pas(main_link) + '">' + see_link + '</a>', data, 1)
+        else:
+            break
+
+    category += '</div>'
+    category = re.sub(' / <\/div>$', '</div>', category)
+
+    if category == '\r\n<div id="cate">분류: </div>':
+        category = ''
+
+    data += category
+    
+    # 마지막 처리
+    data = re.sub('(?P<in><hr id="under_bar" style="margin-top: -5px; margin-bottom: 10px;">)(\r\n)+', '\g<in>', data)
+    data = re.sub('<\/ul>\r\n\r\n', '</ul>\r\n', data)
+    data = re.sub('^(\r\n)+', '', data)
+    data = re.sub('(\r\n)+$', '', data)
+    data = re.sub('(\r\n)?<span id="include"><\/span>(\r\n)?(<span style="margin-left: 20px;"><\/span>)?', '', data)
+    data = re.sub('\r\n', '<br>', data)
+
     return data

+ 0 - 246
set_mark/table.py

@@ -1,246 +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 += 'margin-top: 10px;"'
-    celstyle += '"'
-    rowstyle += '"'
-    table_class += '"'
-
-    return [alltable, rowstyle, celstyle, row, cel, table_class, num]
-
-def table(data):
-    data += '\r\n'
-    data = re.sub('(\r+)', '\r', data)
-    data = re.sub("(?:\|\|\r\n)", "#table-start##table-no-br#", data)
-        
-    while 1:
-        y = re.search("(\|\|(?:(?:(?!\|\|).)+(?:\n*))+)", data)
-        if y:
-            a = y.groups()
-            
-            mid_data = re.sub("\|\|", "#table-start#", 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-start#", "||", data)
-    data = re.sub("#table-no-br#", "\r\n", data)
-    
-    while 1:
-        m = re.search("(?:\n|<br>|<span>)(\|\|(?:(?:(?:.*)\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 style='margin-top: 10px;'><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|<br>|<span>)(\|\|(?:(?:(?:.*)\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) 
-    data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
-    data = re.sub('&lt;math&gt;(?P<in>(?:(?!&lt;\/math&gt;).)*)&lt;\/math&gt;', '[math]\g<in>[/math]', data)
-
-    while 1:
-        if re.search("\n-{4,9}( *)\r\n", data):
-            data = re.sub("\n-{4,9}( *)\r\n", "\n<hr style='margin-top: 10px; margin-bottom: -10px;'>\n", data, 1)
-        else:
-            break
-        
-    return data

+ 0 - 82
set_mark/toc_pas.py

@@ -1,82 +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', '#table-no-br#<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()

+ 5 - 2
version.md

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