Просмотр исходного кода

https://github.com/openNAMU/openNAMU/issues/1845

잉여개발기 (SPDV) 2 лет назад
Родитель
Сommit
df1c3c1c73
2 измененных файлов с 68 добавлено и 149 удалено
  1. 67 148
      route/tool/func_render_namumark.py
  2. 1 1
      version.json

+ 67 - 148
route/tool/func_render_namumark.py

@@ -2054,44 +2054,7 @@ class class_do_render_namumark:
             quote_count_max -= 1
             quote_count += 1
 
-        # 일반 리스트
-        list_style = {
-            1 : 'opennamu_list_1',
-            2 : 'opennamu_list_2',
-            3 : 'opennamu_list_3',
-            4 : 'opennamu_list_4'
-        }
-        def do_render_list_sub(match):
-            list_data = match.group(2)
-            list_len = len(match.group(1))
-            if list_len == 0:
-                list_len = 1
-
-            list_style_data = 'opennamu_list_5'
-            if list_len in list_style:
-                list_style_data = list_style[list_len]
-
-            return '<li style="margin-left: ' + str(list_len * 20) + 'px;" class="' + list_style_data + '">' + list_data + '</li>'
-
-        list_regex = r'((?:\n *\* ?[^\n]*)+)\n'
-        list_count_max = len(re.findall(list_regex, self.render_data)) * 3
-        while 1:
-            list_data = re.search(list_regex, self.render_data)
-            if list_count_max < 0:
-                break
-            elif not list_data:
-                break
-            else:
-                list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)\* ?([^\n]*)'
-
-                list_data = re.sub(list_sub_regex, do_render_list_sub, list_data)
-
-                self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)
-
-            list_count_max -= 1
-
-        # 기타 리스트 공통 파트
+        # 리스트 공통 파트
         def int_to_alpha(num):
             alpha_list = string.ascii_lowercase
             alpha_len = len(alpha_list)
@@ -2124,128 +2087,84 @@ class class_do_render_namumark:
             
         list_view_set = get_main_skin_set(self.curs, self.flask_session, 'main_css_list_view_change', self.ip)
         
+        list_style = {
+            1 : 'opennamu_list_1',
+            2 : 'opennamu_list_2',
+            3 : 'opennamu_list_3',
+            4 : 'opennamu_list_4'
+        }
         class do_render_list_int_to:
-            def __init__(self, do_type, list_view_set = ''):
-                self.list_num = []
-                self.do_type = do_type
+            def __init__(self, list_view_set = ''):
+                self.list_num = {}
                 self.list_view_set = list_view_set
 
             def __call__(self, match):
-                list_data = match.group(3)
-                list_start = match.group(2)
-                list_len = len(match.group(1))
-                if list_len == 0:
-                    list_len = 1
+                if match.group(4):
+                    list_data = match.group(5)
+                    list_len = len(match.group(1))
+                    if list_len == 0:
+                        list_len = 1
 
-                if len(self.list_num) >= list_len:
-                    self.list_num[list_len - 1] += 1
+                    list_style_data = 'opennamu_list_5'
+                    if list_len in list_style:
+                        list_style_data = list_style[list_len]
 
-                    for for_a in range(list_len, len(self.list_num)):
-                        self.list_num[for_a] = 0
+                    return '<li style="margin-left: ' + str(list_len * 20) + 'px;" class="' + list_style_data + '">' + list_data + '</li>'
                 else:
-                    self.list_num += [1] * (list_len - len(self.list_num))
-
-                if list_start:
-                    self.list_num[list_len - 1] = int(list_start)
-
-                if self.do_type == 'int':
-                    if self.list_view_set == 'on':
-                        change_text = str('-'.join([str(for_a) for for_a in self.list_num if for_a != 0]))
-                    else:
-                        change_text = str(self.list_num[list_len - 1])
-                elif self.do_type == 'roman_big':
-                    change_text = int_to_roman(self.list_num[list_len - 1]).upper()
-                elif self.do_type == 'roman_small':
-                    change_text = int_to_roman(self.list_num[list_len - 1]).lower()
-                elif self.do_type == 'alpha_big':
-                    change_text = int_to_alpha(self.list_num[list_len - 1]).upper()
-                else:
-                    change_text = int_to_alpha(self.list_num[list_len - 1]).lower()
-
-                return '<li style="margin-left: ' + str((list_len - 1) * 20) + 'px;" class="opennamu_list_none">' + change_text + '. ' + list_data + '</li>'
-
-        # 숫자 리스트
-        list_regex = r'((?:\n *1\. ?[^\n]*){2,})\n'
-        list_count_max = len(re.findall(list_regex, self.render_data)) * 3
-        while 1:
-            list_data = re.search(list_regex, self.render_data)
-            if list_count_max < 0:
-                break
-            elif not list_data:
-                break
-            else:
-                list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)1\.(?:#([0-9]*))? ?([^\n]*)'
-
-                list_class = do_render_list_int_to('int', list_view_set)
-                list_data = re.sub(list_sub_regex, list_class, list_data)
-
-                self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)
-
-            list_count_max -= 1
-
-        # 소문자 리스트
-        list_regex = r'((?:\n *a\. ?[^\n]*){2,})\n'
-        list_count_max = len(re.findall(list_regex, self.render_data)) * 3
-        while 1:
-            list_data = re.search(list_regex, self.render_data)
-            if list_count_max < 0:
-                break
-            elif not list_data:
-                break
-            else:
-                list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)a.(?:#([0-9]*))? ?([^\n]*)'
-
-                list_class = do_render_list_int_to('alpha_small')
-                list_data = re.sub(list_sub_regex, list_class, list_data)
-
-                self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)
-
-            list_count_max -= 1
-
-        # 대문자 리스트
-        list_regex = r'((?:\n *A\. ?[^\n]*){2,})\n'
-        list_count_max = len(re.findall(list_regex, self.render_data)) * 3
-        while 1:
-            list_data = re.search(list_regex, self.render_data)
-            if list_count_max < 0:
-                break
-            elif not list_data:
-                break
-            else:
-                list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)A.(?:#([0-9]*))? ?([^\n]*)'
-
-                list_class = do_render_list_int_to('alpha_big')
-                list_data = re.sub(list_sub_regex, list_class, list_data)
+                    list_type = match.group(2)
+
+                    do_type = 'int'
+                    if list_type == 'a':
+                        do_type = 'alpha_small'
+                    elif list_type == 'A':
+                        do_type = 'alpha_big'
+                    elif list_type == 'i':
+                        do_type = 'roman_small'
+                    elif list_type == 'I':
+                        do_type = 'roman_big'
+
+                    if not do_type in self.list_num:
+                        self.list_num[do_type] = []
+                    
+                    for for_a in self.list_num:
+                        if for_a != do_type:
+                            self.list_num[for_a] = []
 
-                self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)
+                    list_data = match.group(5)
+                    list_start = match.group(3)
+                    list_len = len(match.group(1))
+                    if list_len == 0:
+                        list_len = 1
 
-            list_count_max -= 1
+                    if len(self.list_num[do_type]) >= list_len:
+                        self.list_num[do_type][list_len - 1] += 1
 
-        # 로마자 대문자 리스트
-        list_regex = r'((?:\n *I\. ?[^\n]*){2,})\n'
-        list_count_max = len(re.findall(list_regex, self.render_data)) * 3
-        while 1:
-            list_data = re.search(list_regex, self.render_data)
-            if list_count_max < 0:
-                break
-            elif not list_data:
-                break
-            else:
-                list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)I.(?:#([0-9]*))? ?([^\n]*)'
+                        for for_a in range(list_len, len(self.list_num[do_type])):
+                            self.list_num[do_type][for_a] = 0
+                    else:
+                        self.list_num[do_type] += [1] * (list_len - len(self.list_num[do_type]))
 
-                list_class = do_render_list_int_to('roman_big')
-                list_data = re.sub(list_sub_regex, list_class, list_data)
+                    if list_start:
+                        self.list_num[do_type][list_len - 1] = int(list_start)
 
-                self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)
+                    if do_type == 'int':
+                        if self.list_view_set == 'on':
+                            change_text = str('-'.join([str(for_a) for for_a in self.list_num[do_type] if for_a != 0]))
+                        else:
+                            change_text = str(self.list_num[do_type][list_len - 1])
+                    elif do_type == 'roman_big':
+                        change_text = int_to_roman(self.list_num[do_type][list_len - 1]).upper()
+                    elif do_type == 'roman_small':
+                        change_text = int_to_roman(self.list_num[do_type][list_len - 1]).lower()
+                    elif do_type == 'alpha_big':
+                        change_text = int_to_alpha(self.list_num[do_type][list_len - 1]).upper()
+                    else:
+                        change_text = int_to_alpha(self.list_num[do_type][list_len - 1]).lower()
 
-            list_count_max -= 1
+                    return '<li style="margin-left: ' + str((list_len - 1) * 20) + 'px;" class="opennamu_list_none">' + change_text + '. ' + list_data + '</li>'
 
-        # 로마자 소문자 리스트
-        list_regex = r'((?:\n *i\. ?[^\n]*){2,})\n'
+        # 숫자 리스트
+        list_regex = r'((?:\n( *)(?:(1|a|A|I|i)\.(?:#([0-9]*))?|(\*)) ?([^\n]*))+)\n'
         list_count_max = len(re.findall(list_regex, self.render_data)) * 3
         while 1:
             list_data = re.search(list_regex, self.render_data)
@@ -2255,9 +2174,9 @@ class class_do_render_namumark:
                 break
             else:
                 list_data = list_data.group(1)
-                list_sub_regex = r'\n( *)i.(?:#([0-9]*))? ?([^\n]*)'
+                list_sub_regex = r'\n( *)(?:(1|a|A|I|i)\.(?:#([0-9]*))?|(\*)) ?([^\n]*)'
 
-                list_class = do_render_list_int_to('roman_small')
+                list_class = do_render_list_int_to(list_view_set)
                 list_data = re.sub(list_sub_regex, list_class, list_data)
 
                 self.render_data = re.sub(list_regex, lambda x : ('\n<front_br><ul class="opennamu_ul">' + list_data + '</ul><back_br>\n'), self.render_data, 1)

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC5-dev33",
+        "r_ver" : "v3.4.6-RC5-dev34",
         "c_ver" : "3500373",
         "s_ver" : "3500112"
     }