Преглед изворни кода

Merge pull request #214 from 2DU/New-Mark

New mark
ect (or 2du) пре 8 година
родитељ
комит
f03d96bdb2

+ 2 - 0
.gitignore

@@ -3,3 +3,5 @@ set.json
 /app_session
 opennamu.db
 image
+.vscode
+set_mark/__pycache__

+ 19 - 19
app.py

@@ -5,6 +5,7 @@ import sqlite3
 import bcrypt
 import os
 import difflib
+from set_mark.macro import savemark
 
 try:
     json_data = open('set.json').read()
@@ -35,6 +36,8 @@ session_opts = {
 
 app = beaker.middleware.SessionMiddleware(app(), session_opts)
 
+from set_mark.mark import *
+from set_mark.mid_pas import *
 from func import *
 
 BaseRequest.MEMFILE_MAX = 1000 ** 4
@@ -1468,7 +1471,7 @@ def revert(name = None, num = None):
                 
             history_plus(name, data[0][0], today, ip, request.forms.send + ' (' + str(num) + '판)', leng)
             
-            namumark(name, data[0][0], 1, 0, 0)
+            namumark(conn, name, data[0][0], 1, 0, 0)
             conn.commit()
             
             return(redirect('/w/' + url_pas(name)))
@@ -1590,21 +1593,18 @@ def edit(name = None, name2 = None, num = None):
             if(not num and request.forms.otent != old[0][0]):
                 return(re_error('/error/12'))
 
-            leng = leng_check(len(request.forms.otent), len(content))
-            
             if(num):
                 content = old[0][0].replace(request.forms.otent, content)
-                
+
+            leng = leng_check(len(request.forms.otent), len(content))
             curs.execute("update data set data = ? where title = ?", [content, name])
         else:
             leng = '+' + str(len(content))
-
             curs.execute("insert into data (title, data, acl) values (?, ?, '')", [name, content])
-        
-        history_plus(name, content, today, ip, send_p(request.forms.send), leng)
 
+        history_plus(name, content, today, ip, send_p(request.forms.send), leng)
         curs.execute("delete from back where link = ?", [name])
-        namumark(name, content, 1, 0, 0)
+        namumark(conn, name, content, 1, 0, 0)
         conn.commit()
         
         return(redirect('/w/' + url_pas(name)))
@@ -1699,7 +1699,7 @@ def preview(name = None, num = None):
          
     newdata = request.forms.content
     newdata = re.sub('^#(?:redirect|넘겨주기) (?P<in>[^\n]*)', ' * [[\g<in>]] 문서로 넘겨주기', newdata)
-    enddata = namumark(name, newdata, 0, 0, 0)
+    enddata = namumark(conn, name, newdata, 0, 0, 0)
 
     if(num):
         action = '/section/' + str(num)
@@ -1873,7 +1873,7 @@ def other():
         html_minify(
             template('index', 
                 imp = ['기타 메뉴', wiki_set(1), custom(), other2([0, 0])],
-                data = namumark('', '[목차(없음)]\r\n' + \
+                data = namumark(conn, '', '[목차(없음)]\r\n' + \
                                     '== 기록 ==\r\n' + \
                                     ' * [[wiki:block_log|차단 기록]]\r\n' + \
                                     ' * [[wiki:user_log|가입 기록]]\r\n' + \
@@ -1904,7 +1904,7 @@ def manager(num = 1):
             html_minify(
                 template('index', 
                     imp = ['관리자 메뉴', wiki_set(1), custom(), other2([0, 0])],
-                    data = namumark('', '[목차(없음)]\r\n' + \
+                    data = namumark(conn, '', '[목차(없음)]\r\n' + \
                                         '== 목록 ==\r\n' + \
                                         ' * [[wiki:manager/2|문서 ACL]]\r\n' + \
                                         ' * [[wiki:manager/3|사용자 검사]]\r\n' + \
@@ -2463,7 +2463,7 @@ def topic(name = None, sub = None):
                                 </td> \
                             </tr> \
                             <tr> \
-                                <td>' + namumark('', d[0], 0, 0, 0) + '</td> \
+                                <td>' + namumark(conn, '', d[0], 0, 0, 0) + '</td> \
                             </tr> \
                         </tbody> \
                     </table> \
@@ -2487,7 +2487,7 @@ def topic(name = None, sub = None):
             else:
                 bd = ''
 
-            p = namumark('', p, 0, 0, 0)
+            p = namumark(conn, '', p, 0, 0, 0)
 
             ip = ip_pas(d[3])
 
@@ -3348,7 +3348,7 @@ def read_view(name = None, num = None, redirect = None):
     if(redirect):
         elsedata = re.sub("^#(?:redirect|넘겨주기) (?P<in>[^\n]*)", " * [[\g<in>]] 문서로 넘겨주기", elsedata)
             
-    enddata = namumark(name, elsedata, 0, 0, 1)
+    enddata = namumark(conn, name, elsedata, 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), '역링크']]
@@ -3384,7 +3384,7 @@ def read_view(name = None, num = None, redirect = None):
         html_minify(
             template('index', 
                 imp = [name, wiki_set(1), custom(), other2([sub + acl, r_date])],
-                data = enddata + namumark(name, div, 0, 0, 0),
+                data = enddata + namumark(conn, name, div, 0, 0, 0),
                 menu = menu
             )
         )
@@ -3558,7 +3558,7 @@ def user_info():
         html_minify(
             template('index', 
                 imp = ['사용자 메뉴', wiki_set(1), l, other2([0, 0])],
-                data =  ip + '<br><br>' + namumark('',  '권한 상태 : ' + acl + '\r\n' + \
+                data =  ip + '<br><br>' + namumark(conn, '',  '권한 상태 : ' + acl + '\r\n' + \
                                                         '[목차(없음)]\r\n' + \
                                                         '== 로그인 ==\r\n' + \
                                                         plus + '\r\n' + \
@@ -3730,7 +3730,7 @@ def count_edit(name = None):
         html_minify(
             template('index', 
                 imp = ['기여 횟수', wiki_set(1), custom(), other2([0, 0])],
-                data = namumark("", "||<-2><:> " + that + " ||\r\n||<:> 기여 횟수 ||<:> " + str(data) + "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
+                data = namumark(conn, "", "||<-2><:> " + that + " ||\r\n||<:> 기여 횟수 ||<:> " + str(data) + "||\r\n||<:> 토론 횟수 ||<:> " + str(t_data) + "||", 0, 0, 0),
                 menu = [['user', '사용자']]
             )
         )
@@ -3778,8 +3778,8 @@ def error_404(error):
 def error_500(error):
     try:
         curs.execute("select title from data limit 1")
-        return('<!-- Splash, Spark, and Shining the Summer! 코코데맛떼나이데 잇쇼니코나캬, 다! Summer time (Oh ya! Summer time!!) 톤데모나이 나츠니나리소오 키미모카쿠고와 데키타카나? 히토리맛떼타라 앗토이우마니 바이바이 Summer time (Oh ya! Summer time!!) 오이데카레루노가 키라이나라 스구니오이데요 코코로우키우키 우키요노도리-무 비-치 세카이데 보우켄시요오 "보-옷"토 스키챠못타이나이 "규-웃"토 코이지칸가호시이? 닷타라(Let\'s go!) 닷타라(Let\'s go!) 코토시와 이치도키리사 아소보오 Splash! (Splash!!) 토비콘다 우미노아오사가(Good feeling) 오와라나이 나츠에노 토비라오 유메밋테루토 싯테루카이? 아소보오 Splash! (Splash!!) 토비콘데 미세타아토 키미가 타메랏테루(나라바) 요우샤나쿠 Summer Summer Summer에 츠레텟챠우카라! -->' + redirect('/w/' + url_pas(wiki_set(2))))
+        return('<!-- Splash, Spark, and Shining the Summer! 코코데맛떼나이데 잇쇼니코나캬, 다! Summer time (Oh ya! Summer time!!) 톤데모나이 나츠니나리소오 키미모카쿠고와 데키타카나? 히토리맛떼타라 앗토이우마니 바이바이 Summer time (Oh ya! Summer time!!) 오이데카레루노가 키라이나라 스구니오이데요 코코로우키우키 우키요노도리-무 비-치 세카이데 보우켄시요오 "보-옷"토 스키챠못타이나이 "규-웃"토 코이지칸가호시이? 닷타라(Let\'s go!) 닷타라(Let\'s go!) 코토시와 이치도키리사 아소보오 Splash! (Splash!!) 토비콘다 우미노아오사가(Good feeling) 오와라나이 나츠에노 토비라오 유메밋테루토 싯테루카이? 아소보오 Splash! (Splash!!) 토비콘데 미세타아토 키미가 타메랏테루(나라바) 요우샤나쿠 Summer Summer Summer에 츠레텟챠우카라! -->' + error)
     except:
         return('<!-- 아카이 타이요노 도레스데 오도루 와타시노 코토 미츠메테이루노 메오 소라시타이 데모 소라세나이 아아 죠네츠데 야카레타이 도키메키 이죠노 리즈무 코요이 시리타쿠테 이츠모요리 타이탄나 코토바오 츠부야이타 지분노 키모치나노니 젠젠 와카라나쿠 (낫챠이타이나) 리세이카라 시레이가 (토도카나이) 콘토로-루 후카노 손나 코이오 시타놋테 코에가 토도이테시맛타 하즈카시잇테 오모우케도 못토 시리타이노 못토 시리타이노 이케나이 유메다토 키즈키나가라 아카이 타이요노 도레스데 오도루 와타시노 코토 미츠메루 히토미 메오 소라시타이 데모 소라세나이 마나츠와 다레노 모노 아나타토 와타시노 모노니시타이 (닷테네) 코코로가 토마레나이 키세츠니 하지메테 무네노 토비라가 아이테 시마이소오요 You knock knock my heart!! -->' + redirect('/setup'))
     
-run(app = app, server = 'tornado', host = '0.0.0.0', port = int(set_data['port']))
+run(app = app, server = 'tornado', host = '0.0.0.0', port = int(set_data['port']), debug = True)

+ 0 - 0
mark.py → back_up_mark.py


+ 29 - 3
func.py

@@ -3,7 +3,11 @@ from bottle.ext import beaker
 import json
 import sqlite3
 from hashlib import md5
+from urllib import parse
+import re
+import html
 from css_html_js_minify import html_minify
+import time
 
 json_data = open('set.json').read()
 set_data = json.loads(json_data)
@@ -19,7 +23,29 @@ session_opts = {
 
 app = beaker.middleware.SessionMiddleware(app(), session_opts)
 
-from mark import *
+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():
+    session = request.environ.get('beaker.session')
+    try:
+        if(session.get('Now') == 1):
+            ip = format(session['DREAMER'])
+        else:
+            if(request.environ.get('HTTP_X_FORWARDED_FOR')):
+                ip = request.environ.get('HTTP_X_FORWARDED_FOR')
+            else:
+                ip = request.environ.get('REMOTE_ADDR')
+    except:
+        ip = 'None'
+
+    return(ip)
+    
+def url_pas(data):
+    return(parse.quote(data).replace('/','%2F'))
 
 def other2(d):
     g = ''
@@ -320,7 +346,7 @@ def rb_plus(block, end, today, blocker, why):
     curs.execute("insert into rb (block, end, today, blocker, why) values (?, ?, ?, ?, ?)", [block, end, today, blocker, why])
 
 def history_plus(title, data, date, ip, send, leng):
-    curs.execute("select id from history where title = ? order by id+0 desc limit 1", [title])
+    curs.execute("select id from history where title = ? order by id + 0 desc limit 1", [title])
     d = curs.fetchall()
     if(d):
         curs.execute("insert into history (id, title, data, date, ip, send, leng) values (?, ?, ?, ?, ?, ?, ?)", [str(int(d[0][0]) + 1), title, data, date, ip, send, leng])
@@ -340,7 +366,7 @@ def leng_check(a, b):
     return(c)
 
 def redirect(data):
-    return('<meta http-equiv="refresh" content="0;url=' + data + '" />')
+    return('<meta http-equiv="refresh" content="0; url=' + data + '">')
 
 def re_error(data):
     if(data == '/ban'):

+ 0 - 0
set_mark/__init__.py


+ 14 - 0
set_mark/blockquote.py

@@ -0,0 +1,14 @@
+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)

+ 22 - 0
set_mark/end.py

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

+ 70 - 0
set_mark/footnote.py

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

+ 37 - 0
set_mark/html_pas.py

@@ -0,0 +1,37 @@
+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']):
+                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])
+                        if(v_src):
+                            if(not v_src.groups()[0] in ["www.youtube.com", "serviceapi.nmv.naver.com", "tv.kakao.com", "www.google.com", "serviceapi.rmcnmv.naver.com"]):
+                                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)

+ 58 - 0
set_mark/include_pas.py

@@ -0,0 +1,58 @@
+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 = []
+    
+    include = re.compile("\[include\(((?:(?!\)\]|,).)*)((?:(?:,\s?(?:(?!\)\]).)*))+)?\)\]")
+    m = include.findall(data)
+    for results in m:
+        if(results[0] == title):
+            data = include.sub("<b>" + results[0] + "</b>", data, 1)
+        else:
+            curs.execute("select data from data where title = ?", [results[0]])
+            in_con = curs.fetchall()
+            
+            backlink += [[title, results[0], 'include']]
+            if(in_con):                        
+                in_data = in_con[0][0]
+                in_data = include.sub("", 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)
+                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], in_data)
+                            a = re.sub("([^= ,]*)\=([^,]*)", "", a, 1)
+                        else:
+                            break       
+
+                in_data = toc_pas.toc_pas(in_data, results[0], num, toc_y)
+                            
+                data = include.sub('\n<nobr><a id="include_link" href="/w/' + url_pas(results[0]) + '">[' + results[0] + ' 이동]</a><div>' + in_data + '</div><nobr>\n', data, 1)
+            else:
+                data = include.sub("<a class=\"not_thing\" href=\"/w/" + url_pas(results[0]) + "\">" + results[0] + "</a>", data, 1)
+
+    return([data, category, fol_num, backlink])

+ 37 - 0
set_mark/indent.py

@@ -0,0 +1,37 @@
+import re
+
+def indent(data):
+    while(1):
+        m = re.search("(\n(?:(?:( +)\*\s(?:[^\n]*))\n?)+)", data)
+        if(m):
+            result = m.groups()
+            end = str(result[0])
+
+            while(1):
+                isspace = re.search("( +)\*\s([^\n]*)", end)
+                if(isspace):
+                    spacebar = isspace.groups()
+                    up = len(spacebar[0]) * 20
+                    end = re.sub("( +)\*\s([^\n]*)", "<li style='margin-left:" + str(up) + "px'>" + spacebar[1] + "</li>", end, 1)
+                else:
+                    break
+
+            end = re.sub("\n", '', end)
+            data = re.sub("(\n(?:(?:( +)\*\s(?:[^\n]*))\n?)+)", '<ul style="margin-top: 10px; margin-bottom: 10px;" id="list">' + end + '</ul>', data, 1)
+        else:
+            break
+
+    while(1):
+        b = re.search("(<\/h[0-9]>|\n)( +)", data)
+        if(b):
+            result = b.groups()
+            up = re.sub(' ', '<span id="in"></span>', result[1])
+
+            if(re.search('<\/h[0-9]>', result[0])):
+                data = re.sub("(?P<in>\/h[0-9]>)( +)", '\g<in>' + up, data, 1)
+            else:
+                data = re.sub("(?:\n)( +)", '<br>' + up, data, 1)
+        else:
+            break
+            
+    return(data)

+ 160 - 0
set_mark/link.py

@@ -0,0 +1,160 @@
+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):
+            if(num == 1):
+                backlink += [[title, g, 'cat']]
+                
+            if(category == ''):
+                curs.execute("select title from data where title = ?", [g])
+                exists = curs.fetchall()
+                if(exists):
+                    red = ""
+                else:
+                    red = 'class="not_thing"'
+                    
+                category += '<a ' + red + ' href="/w/' + url_pas(g) + '">' + re.sub("분류:", "", g) + '</a>'
+            else:
+                curs.execute("select title from data where title = ?", [g])
+                exists = curs.fetchall()
+                if(exists):
+                    red = ""
+                else:
+                    red = 'class="not_thing"'
+                    
+                category += ' / ' + '<a ' + red + ' href="/w/' + url_pas(g) + '">' + re.sub("분류:", "", g) + '</a>'
+        
+        data = re.sub("\[\[(분류:(?:(?:(?!\]\]).)*))\]\]", '', data, 1)
+    
+    test = re.findall('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', data)
+    if(test):
+        for wiki in test:
+            if(wiki[1]):
+                data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[1] + '</a>', data, 1)
+            else:
+                data = re.sub('\[\[wiki:([^|\]]+)(?:\|([^\]]+))?\]\]', '<a id="inside" href="/' + wiki[0] + '">' + wiki[0] + '</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']]
+                        
+                    img = span[0] + '<img src="/image/' + sha224(f_d.groups()[0]) + '.' + f_d.groups()[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?:\/\/', 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="' + 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 = href.replace('&#x27;', "'").replace('&quot;', '"').replace('\\\\', '<slash>').replace('\\', '').replace('<slash>', '\\')
+                    
+                    if(num == 1):
+                        backlink += [[title, a, '']]
+                    
+                    curs.execute("select title from data where title = ?", [a])
+                    if(not curs.fetchall()):
+                        no = 'class="not_thing"'
+                        
+                        if(num == 1):
+                            backlink += [[title, a, 'no']]
+                    else:
+                        no = ''
+                    
+                    data = link.sub('<a ' + no + ' title="' + href + sh + '" href="/w/' + url_pas(a) + sh + '">' + view.replace('\\', '\\\\') + '</a>', data, 1)
+        else:
+            break
+            
+    data = data.replace('\\', '&#92;')
+
+    return([data, category, backlink])

+ 123 - 0
set_mark/macro.py

@@ -0,0 +1,123 @@
+from bottle import request, app
+from bottle.ext import beaker
+from urllib import parse
+import time
+import datetime
+import re
+import json
+
+session_opts = {
+    'session.type': 'dbm',
+    'session.data_dir': './app_session/',
+    'session.auto': 1
+}
+
+app = beaker.middleware.SessionMiddleware(app(), session_opts)
+
+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():
+    session = request.environ.get('beaker.session')
+    try:
+        if(session.get('Now') == 1):
+            ip = format(session['DREAMER'])
+        else:
+            if(request.environ.get('HTTP_X_FORWARDED_FOR')):
+                ip = request.environ.get('HTTP_X_FORWARDED_FOR')
+            else:
+                ip = request.environ.get('REMOTE_ADDR')
+    except:
+        ip = 'None'
+
+    return(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\(([^, )]*)(,[^)]*)?\)\]")
+        m = com.search(data)
+        if(m):
+            src = ''
+            width = '560'
+            height = '315'
+            time = '0'
+            
+            result = m.groups()
+            if(result[0]):
+                yudt = re.search('(?:\?v=(.*)|\/([^/?]*)|^([a-zA-Z0-9\-_]*))$', result[0])
+                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[1]):
+                mdata = re.search('width=([0-9%]*)', result[1])
+                if(mdata):
+                    width = mdata.groups()[0]
+                
+                mdata = re.search('height=([0-9%]*)', result[1])
+                if(mdata):
+                    height = mdata.groups()[0]
+                    
+                mdata = re.search('start=([0-9]*)', result[1])
+                if(mdata):
+                    time = mdata.groups()[0]
+
+            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:
+            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)

+ 84 - 0
set_mark/mark.py

@@ -0,0 +1,84 @@
+from . import start
+from . import mid_pas
+from . import html_pas
+from . import include_pas
+from . import macro
+from . import redirect_pas
+from . import blockquote
+from . import toc_pas
+from . import text_help
+from . import link
+from . import indent
+from . import footnote
+from . import table
+from . import end
+import re
+import html
+import sqlite3
+from urllib import parse
+import time
+import asyncio
+
+def send_p(d):
+    d = html.escape(d)
+
+    js_p = re.compile('javascript:', re.I)
+    d = js_p.sub('', d)
+
+    d = re.sub('&lt;a href="(?:[^"]*)"&gt;(?P<in>(?:(?!&lt;).)*)&lt;\/a&gt;', '<a href="' + url_pas('\g<in>') + '">\g<in></a>', d)  
+
+    return(d)
+
+def url_pas(data):
+    return(parse.quote(data).replace('/','%2F'))
+    
+async def plusing(conn, name, link, backtype):
+    curs = conn.cursor()
+    curs.execute("select title from back where title = ? and link = ? and type = ?", [name, link, backtype])
+    if(not curs.fetchall()):
+        curs.execute("insert into back (title, link, type) values (?, ?,  ?)", [name, link, backtype])
+
+def namumark(conn, title, data, num, in_c, toc_y):  
+    data = start.start(data)
+    data = html_pas.html_pas(data)
+    
+    fol_num = 0
+    a = mid_pas.mid_pas(data, fol_num, 0, in_c)
+    data = a[0]
+    fol_num = a[1]
+
+    a = include_pas.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("\r\n##\s?([^\n]*)\r\n", "\r\n", data)    
+    a = redirect_pas.redirect_pas(data, title, backlink)
+    data = a[0]
+    backlink = a[1]
+    
+    data = blockquote.blockquote(data)
+    data = toc_pas.toc_pas(data, title, num, toc_y)
+    data = text_help.text_help(data)
+    data = macro.macro(data)
+    
+    a = link.link(conn, title, data, num, category, backlink)
+    data = a[0]
+    category = a[1]
+    backlink = a[2]
+    
+    data = indent.indent(data)
+    data = footnote.footnote(data, fol_num)
+    data = table.table(data)
+    data = end.end(data, category)
+    
+    if(num == 1):        
+        asyncio.set_event_loop(asyncio.new_event_loop())
+        loop = asyncio.get_event_loop()
+        for d4 in backlink:
+            loop.run_until_complete(plusing(conn, d4[0], d4[1], d4[2]))
+        loop.close()
+        conn.commit()
+        
+    return(data)

+ 124 - 0
set_mark/mid_pas.py

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

+ 24 - 0
set_mark/redirect_pas.py

@@ -0,0 +1,24 @@
+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) + '/from/' + url_pas(title) + sh + '" />', data, 1)
+        
+    return([data, backlink])

+ 9 - 0
set_mark/start.py

@@ -0,0 +1,9 @@
+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'
+        
+    return(data)

+ 209 - 0
set_mark/table.py

@@ -0,0 +1,209 @@
+import re
+
+def table_p(d, d2):
+    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):
+        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;'
+
+    text_class = re.search("&lt;table\s?class=((?:(?!&gt;).)+)&gt;", d)
+    if(text_class):
+        d = text_class.groups()
+        table_class += d[0]
+        
+    alltable += '"'
+    celstyle += '"'
+    rowstyle += '"'
+    table_class += '"'
+
+    return([alltable, rowstyle, celstyle, row, cel, table_class])
+
+def table(data):
+    data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
+        
+    while(1):
+        y = re.search("(\|\|(?:(?:(?:(?:(?!\|\|).)*)(?:\n?))+))", data)
+        if(y):
+            a = y.groups()
+            
+            mid_data = re.sub("\|\|", "#table#", a[0])
+            mid_data = re.sub("\r\n", "<br>", mid_data)
+            
+            data = re.sub("(\|\|((?:(?:(?:(?!\|\|).)*)(?:\n?))+))", mid_data, data, 1)
+        else:
+            break
+            
+    data = re.sub("#table#", "||", data)
+    data = re.sub("<tablenobr>", "\r\n", data)
+    
+    while(1):
+        m = re.search("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", data)
+        if(m):
+            results = m.groups()
+            table = results[0]
+            while(1):
+                a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
+                if(a):
+                    row = ''
+                    cel = ''
+                    celstyle = ''
+                    rowstyle = ''
+                    alltable = ''
+                    table_d = ''
+
+                    result = a.groups()
+                    if(result[1]):
+                        table_d = table_p(result[1], result[0])
+                        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]
+                            
+                        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)) + '"'
+                        table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?",   "<table><tbody><tr><td " + cel + ">", table, 1)
+                else:
+                    break
+                    
+            table = re.sub("\|\|$", "</td></tr></tbody></table>", table)
+            
+            while(1):
+                b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
+                if(b):
+                    row = ''
+                    cel = ''
+                    celstyle = ''
+                    rowstyle = ''
+                    table_d = ''
+
+                    result = b.groups()
+                    if(result[1]):
+                        table_d = table_p(result[1], result[0])
+                        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)) + '"'
+                        table = re.sub("\|\|\r\n(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td></tr><tr><td " + cel + ">", table, 1)
+                else:
+                    break
+
+            while(1):
+                c = re.search("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
+                if(c):
+                    row = ''
+                    cel = ''
+                    celstyle = ''
+                    table_d = ''
+
+                    result = c.groups()
+                    if(result[1]):
+                        table_d = table_p(result[1], result[0])
+                        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)) + '"'
+                        table = re.sub("(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", "</td><td " + cel + ">", table, 1)
+                else:
+                    break
+            
+            data = re.sub("(\|\|(?:(?:(?:.*)\n?)\|\|)+)", table, data, 1)
+        else:
+            break
+        
+    return(data)

+ 14 - 0
set_mark/text_help.py

@@ -0,0 +1,14 @@
+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('&lt;math&gt;(?P<in>((?!&lt;math&gt;).)*)&lt;\/math&gt;', '[math]\g<in>[/math]', data)
+    data = re.sub('{{\|(?P<in>(?:(?:(?:(?!\|}}).)*)(?:\n?))+)\|}}', '<table><tbody><tr><td>\g<in></td></tr></tbody></table>', data)
+    data = re.sub("-{4,11}", "<hr>", data)
+        
+    return(data)

+ 81 - 0
set_mark/toc_pas.py

@@ -0,0 +1,81 @@
+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 = 'style="margin-top: 30px;"'
+                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>. ' + result[1] + '<br>'
+
+            c = re.sub(" $", "", result[1])
+            d = c
+            c = re.sub("\[\[(([^|]*)\|)?(?P<in>[^\]]*)\]\]", "\g<in>", c)
+
+            edit_d = ''
+            if(toc_y == 1):
+                edit_d = ' <span style="font-size:11px;">[<a href="/edit/' + url_pas(title) + '/section/' + str(i[0]) + '">편집</a>]</span>'
+
+            data = re.sub('(={1,6})\s?([^=]*)\s?(?:={1,6})(?:\s+)?\n', '<tablenobr><h' + str(wiki) + ' id="' + c + '" ' + margin + '><a href="#toc" id="s-' + toc + '">' + toc + '.<span style="margin-left: 5px;"></span></a> ' + d + edit_d + '</h' + str(wiki) + '><hr style="margin-top: -5px;">\n', data, 1)
+        else:
+            rtoc += '</div>'
+            
+            break
+    
+    data = re.sub("\[목차\]", rtoc, data)
+
+    return(data)