Explorar o código

include JS 방식으로 변경, 미리보기 구조 변경

Surplus_Up (2DU) %!s(int64=6) %!d(string=hai) anos
pai
achega
6e450c3bae

+ 4 - 2
route/api_w.py

@@ -12,14 +12,16 @@ def api_w_2(conn, name):
     else:
         if acl_check(name, 'render') != 1:
             if flask.request.method == 'POST':
-                json_data = { "title" : name, "data" : render_set(title = name, data = flask.request.form.get('data', '')) }
+                g_data = render_set(title = name, data = flask.request.form.get('data', ''), num = 2)
+                json_data = { "title" : name, "data" : g_data[0], "js_data" : g_data[1] }
                 
                 return flask.jsonify(json_data)
             else:
                 curs.execute("select data from data where title = ?", [name])
                 data = curs.fetchall()
                 if data:
-                    json_data = { "title" : name, "data" : render_set(title = name, data = data[0][0]) }
+                    g_data = render_set(title = name, data = data[0][0], num = 2)
+                    json_data = { "title" : name, "data" : g_data[0], "js_data" : g_data[1] }
                 
                     return flask.jsonify(json_data)
                 else:

+ 1 - 1
route/tool/func.py

@@ -990,7 +990,7 @@ def number_check(data):
 
 def edit_filter_do(data):
     if admin_check(1) != 1:
-        curs.execute("select regex, sub from filter")
+        curs.execute("select regex, sub from filter where regex != ''")
         for data_list in curs.fetchall():
             match = re.compile(data_list[0], re.I)
             if match.search(data):

+ 4 - 1
route/tool/mark.py

@@ -68,4 +68,7 @@ def namumark(title = '', data = None, num = 0):
         
         conn.commit()
         
-    return data[0] + data[1]
+    if num == 2:
+        return [data[0], data[1]]
+    else:
+        return data[0] + data[1]

+ 10 - 26
route/tool/set_mark/namu.py

@@ -371,7 +371,10 @@ def namu(conn, data, title, main_num):
     data = t_data[0]
 
     include_re = re.compile('\[include\(((?:(?!\)\]).)+)\)\]', re.I)
+    i = 0
     while 1:
+        i += 1
+
         include = include_re.search(data)
         if include:
             include = include.groups()[0]
@@ -386,41 +389,22 @@ def namu(conn, data, title, main_num):
 
             backlink += [[title, include_link, 'include']]
 
-            include = re.sub('^((?:(?!,).)+)', '', include)
-            
-            num = 0
-            while 1:
-                include_one_nowiki = re.search('(?:\\\\){2}(.)', include)
-                if include_one_nowiki:
-                    include_one_nowiki = include_one_nowiki.groups()
-
-                    num += 1
-
-                    end_data += [['include_one_nowiki_' + str(num), include_one_nowiki[0], 'normal']]
-
-                    include = re.sub('(?:\\\\){2}(.)', '<span id="include_one_nowiki_' + str(num) + '"></span>', include, 1)
-                else:
-                    break
-
-            curs.execute("select data from data where title = ?", [include_data])
-            include_data = curs.fetchall()
-            if include_data:
-                include_parser = include_re.sub('', include_data[0][0])
-                include_parser = html.escape(include_parser)
+            curs.execute("select title from data where title = ?", [include_data])
+            if curs.fetchall():
+                data = include_re.sub('<div id="include_' + str(i) + '"></div>', data, 1)
 
+                include_plus_data = []
                 while 1:
                     include_plus = re.search(', ?((?:(?!=).)+)=((?:(?!,).)+)', include)
                     if include_plus:
                         include_plus = include_plus.groups()
-                        include_parser = include_parser.replace('@' + include_plus[0] + '@', include_plus[1])
+                        include_plus_data += [[include_plus[0], include_plus[1]]]
 
                         include = re.sub(', ?((?:(?!=).)+)=((?:(?!,).)+)', '', include, 1)
                     else:
                         break
 
-                include_parser = re.sub('\[\[(?:category|분류):(((?!\]\]|#include).)+)\]\]', '', include_parser)
-
-                data = include_re.sub('<include><a id="include_link" href="/w/' + tool.url_pas(include_link) + '">\n[' + include_link + ']</a>\n' + include_parser + '\n</include>', data, 1)
+                plus_data += '<script>load_include("' + include_link + '", "include_' + str(i) + '", ' + str(include_plus_data) + ');</script>'
             else:
                 data = include_re.sub('<a id="not_thing" href="/w/' + tool.url_pas(include_link) + '">' + include_link + '</a>', data, 1)
         else:
@@ -471,7 +455,7 @@ def namu(conn, data, title, main_num):
                         "''' + math.replace('\\', '\\\\').replace('&lt;', '<').replace('&gt;', '>') + '''",
                         document.getElementById("math_''' + str(first) + '''")
                     );
-            </script>
+                </script>
             '''
         else:
             break

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.3-master-02",
+        "r_ver" : "v3.1.3-master-03",
         "c_ver" : "400003",
         "s_ver" : "2"
     }, "stable" : {

+ 36 - 0
views/main_css/js/load_include.js

@@ -0,0 +1,36 @@
+function load_include(title, name, p_data) {
+    var o_data = document.getElementById(name);
+
+    var url = "/api/w/" + encodeURI(title) + "?include=1";
+    var url_2 = "/api/markup";
+    
+    var xhr = new XMLHttpRequest();
+    xhr.open("GET", url, true);
+    xhr.send(null);
+
+    var xhr_2 = new XMLHttpRequest();
+    xhr_2.open("GET", url_2, true);
+    xhr_2.send(null);
+
+    xhr.onreadystatechange = function() {
+        if(xhr.readyState === 4 && xhr.status === 200) {
+            var o_p_data = JSON.parse(xhr.responseText);
+            var g_data = o_p_data['data'];
+            
+            for(key in p_data) {
+                try {
+                    patt = new RegExp('@' + p_data[key][0] + '@');
+                    g_data = g_data.replace(patt, p_data[key][1]);
+                } catch {}
+            }
+
+            o_data.innerHTML = g_data;
+
+            js_data = o_p_data['js_data'];
+            js_data = js_data.replace(/<script>/g, '');
+            js_data = js_data.replace(/<\/script>/g, '\n');
+
+            eval(js_data)
+        }
+    }
+}

+ 7 - 9
views/main_css/js/load_preview.js

@@ -18,17 +18,15 @@ function load_preview(name) {
 
     xhr.onreadystatechange = function() {
         if(xhr.readyState === 4 && xhr.status === 200) {
-            p_data.innerHTML = JSON.parse(xhr.responseText)['data'];
+            var o_p_data = JSON.parse(xhr.responseText);
 
-            xhr_2.onreadystatechange = function() {
-                if(xhr_2.readyState === 4 && xhr_2.status === 200) {
-                    markup = JSON.parse(xhr_2.responseText)['markup'];
+            p_data.innerHTML = o_p_data['data'];
 
-                    if(markup === 'markdown') {
-                        render_markdown();
-                    }
-                }
-            }
+            js_data = o_p_data['js_data'];
+            js_data = js_data.replace(/<script>/g, '');
+            js_data = js_data.replace(/<\/script>/g, '\n');
+
+            eval(js_data)
         }
     }
 }