Pārlūkot izejas kodu

마크다운 문법 왕창 다듬음

잉여개발기 (SPDV) 5 gadi atpakaļ
vecāks
revīzija
172c3a3b40
3 mainītis faili ar 84 papildinājumiem un 20 dzēšanām
  1. 6 1
      route/edit.py
  2. 77 18
      route/tool/set_mark/markdown.py
  3. 1 1
      version.json

+ 6 - 1
route/edit.py

@@ -19,7 +19,12 @@ def edit_2(conn, name):
     ip = ip_check()
     ip = ip_check()
     section = flask.request.args.get('section', None)
     section = flask.request.args.get('section', None)
     if section:
     if section:
-        section = int(number_check(section))
+        curs.execute(db_change("select data from other where name = 'markup'"))
+        markup = curs.fetchall()
+        if markup[0][0] == 'namumark':
+            section = int(number_check(section))
+        else:
+            return redirect('/edit/' + url_pas(name))
 
 
     if acl_check(name) == 1:
     if acl_check(name) == 1:
         return re_error('/ban')
         return re_error('/ban')

+ 77 - 18
route/tool/set_mark/markdown.py

@@ -6,22 +6,50 @@ import re
 
 
 class head_render:
 class head_render:
     def __init__(self):
     def __init__(self):
-        pass
+        self.head_level = [0, 0, 0, 0, 0, 0]
+        self.toc_data = '' + \
+            '<div id="toc">' + \
+                '<span id="toc_title">TOC</span>' + \
+                '<br>' + \
+                '<br>' + \
+        ''
+        self.toc_num = 0
 
 
     def __call__(self, match):
     def __call__(self, match):
-        head_len = str(len(match[1]))
+        head_len_num = len(match[1])
+        head_len = str(head_len_num)
+        head_len_num -= 1
         head_data = match[2]
         head_data = match[2]
+        self.head_level[head_len_num] += 1
+        for i in range(head_len_num + 1, 6):
+            self.head_level[i] = 0
+        toc_num_str = str(self.toc_num)
+        self.toc_num += 1
+        head_level_str = ('.'.join([str(i) for i in self.head_level]) + '.').replace('0.', '')
+        head_level_str_2 = re.sub(r'\.$', '', head_level_str)
 
 
-        return '<h' + head_len + '>' + head_data + '</h' + head_len + '>'
+        self.toc_data += '<a href="#s-' + head_level_str_2 + '">' + head_level_str + '</a> ' + head_data + '<br>'
+        return '<h' + head_len + ' id="s-' + head_level_str_2 + '"><a href="#toc">' + head_level_str + '</a> ' + head_data + '</h' + head_len + '>'
+
+    def get_toc(self):
+        return self.toc_data + '</div>'
 
 
 class link_render:
 class link_render:
-    def __init__(self):
-        pass
+    def __init__(self, plus_data, include_name):
+        self.str_e_link_id = 0
+        self.plus_data = ''
+        self.include_name = include_name
 
 
     def __call__(self, match):
     def __call__(self, match):
-        if match[1] == '!':
+        str_e_link_id = str(self.str_e_link_id)
+        self.str_e_link_id += 1
+
+        if match[1] == '!':    
+            file_name = ''
             if re.search(r'^http(s)?:\/\/', match[3], flags = re.I):
             if re.search(r'^http(s)?:\/\/', match[3], flags = re.I):
-                return '<img alt="' + match[2] + '" src="' + match[3] + '">'
+                file_src = match[3]
+                file_alt = match[3]
+                exist = '1'
             else:
             else:
                 file_name = re.search(r'^([^.]+)\.([^.]+)$', match[3])
                 file_name = re.search(r'^([^.]+)\.([^.]+)$', match[3])
                 if file_name:
                 if file_name:
@@ -33,23 +61,52 @@ class link_render:
 
 
                 file_src = '/image/' + tool.sha224_replace(file_name) + '.' + file_end
                 file_src = '/image/' + tool.sha224_replace(file_name) + '.' + file_end
                 file_alt = 'file:' + file_name + '.' + file_end
                 file_alt = 'file:' + file_name + '.' + file_end
+                exist = None
 
 
-                return '' + \
-                    '<img class="' + include_num + 'file_finder_1" alt="' + match[2] + '" src="' + file_src + '">' + \
-                    '<a class="' + include_num + 'file_finder_2" id="not_thing" href="/upload?name=' + tool.url_pas(file_name) + '">' + file_alt + '</a>' + \
-                ''
+            return '' + \
+                '<span  class="' + self.include_name + 'file_finder" ' + \
+                        'under_alt="' + file_alt + '" ' + \
+                        'under_src="' + file_src + '" ' + \
+                        'under_href="' + ("out_link" if exist else '/upload?name=' + tool.url_pas(file_name)) + '">' + \
+                '</span>' + \
+            ''
         else:
         else:
             if re.search(r'^http(s)?:\/\/', match[3], flags = re.I):
             if re.search(r'^http(s)?:\/\/', match[3], flags = re.I):
-                return '<a id="out_link" href="' + match[3] + '">' + match[2] + '</a>'
+                self.plus_data += '' + \
+                    'document.getElementsByName("' + self.include_name + 'set_link_' + str_e_link_id + '")[0].href = ' + \
+                        '"' + match[3] + '";' + \
+                    '\n' + \
+                ''
+
+                return '<a  id="out_link" ' + \
+                            'href="" ' + \
+                            'name="' + self.include_name + 'set_link_' + str_e_link_id + '">' + match[2] + '</a>'
             else:
             else:
-                return '<a class="' + include_num + 'link_finder" href="/w/' + match[3] + '">' + match[2] + '</a>'
+                self.plus_data += '' + \
+                    'document.getElementsByName("' + self.include_name + 'set_link_' + str_e_link_id + '")[0].href = ' + \
+                        '"/w/' + tool.url_pas(match[3]) + '";' + \
+                    '\n' + \
+                ''
+                self.plus_data += '' + \
+                    'document.getElementsByName("' + self.include_name + 'set_link_' + str_e_link_id + '")[0].title = ' + \
+                        '"' + match[3] + '";' + \
+                    '\n' + \
+                ''
+
+                return '<a  class="' + self.include_name + 'link_finder" ' + \
+                            'title="" ' + \
+                            'href="" ' + \
+                            'name="' + self.include_name + 'set_link_' + str_e_link_id + '">' + match[2] + '</a>'
+
+    def get_plus_data(self):
+        return self.plus_data
 
 
-def markdown(conn, data, title, include_num):
+def markdown(conn, data, title, include_name):
     backlink = []
     backlink = []
-    include_num = include_num + '_' if include_num else ''
+    include_name = include_name + '_' if include_name else ''
     plus_data = '' + \
     plus_data = '' + \
-        'get_link_state("' + include_num + '");\n' + \
-        'get_file_state("' + include_num + '");\n' + \
+        'get_link_state("' + include_name + '");\n' + \
+        'get_file_state("' + include_name + '");\n' + \
     ''
     ''
 
 
     data = html.escape(data)
     data = html.escape(data)
@@ -59,10 +116,12 @@ def markdown(conn, data, title, include_num):
     head_r = r'\n(#{1,6}) ?([^\n]+)'
     head_r = r'\n(#{1,6}) ?([^\n]+)'
     head_do = head_render()
     head_do = head_render()
     data = re.sub(head_r, head_do, data)
     data = re.sub(head_r, head_do, data)
+    data = head_do.get_toc() + data
 
 
     link_r = r'(!)?\[((?:(?!\]\().)+)\]\(([^\]]+)\)'
     link_r = r'(!)?\[((?:(?!\]\().)+)\]\(([^\]]+)\)'
-    link_do = link_render()
+    link_do = link_render(plus_data, include_name)
     data = re.sub(link_r, link_do, data)
     data = re.sub(link_r, link_do, data)
+    plus_data = link_do.get_plus_data() + plus_data
 
 
     data = re.sub(r'\*\*((?:(?!\*\*).)+)\*\*', '<b>\1</b>', data)
     data = re.sub(r'\*\*((?:(?!\*\*).)+)\*\*', '<b>\1</b>', data)
     data = re.sub(r'__((?:(?!__).)+)__', '<i>\1</i>', data)
     data = re.sub(r'__((?:(?!__).)+)__', '<i>\1</i>', data)

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
 {
     "master" : {
     "master" : {
-        "r_ver" : "v3.2.0-master-14",
+        "r_ver" : "v3.2.0-master-15",
         "c_ver" : "3200900",
         "c_ver" : "3200900",
         "s_ver" : "9"
         "s_ver" : "9"
     }, "stable" : {
     }, "stable" : {