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

나무위키 추가 문법 지원

Surplus_Up (2DU) 6 лет назад
Родитель
Сommit
f48f8ba486
4 измененных файлов с 94 добавлено и 69 удалено
  1. 3 3
      route/tool/func.py
  2. 83 58
      route/tool/set_mark/namumark.py
  3. 6 6
      route/topic_tool.py
  4. 2 2
      version.json

+ 3 - 3
route/tool/func.py

@@ -188,9 +188,6 @@ def update(ver_num):
         print('Add init set')
         set_init()
 
-    if ver_num < 3160500:
-        curs.execute(db_change('delete from cache_data'))
-
     if ver_num < 3170002:
         curs.execute(db_change("select html from html_filter where kind = 'extension'"))
         if not curs.fetchall():
@@ -204,6 +201,9 @@ def update(ver_num):
             curs.execute(db_change("update topic set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
             curs.execute(db_change("update rd set code = ? where title = ? and sub = ?"), [i[2], i[0], i[1]])
 
+    if ver_num < 3171100:
+        curs.execute(db_change('delete from cache_data'))
+
     conn.commit()
     print('Update pass')
     print('----')

+ 83 - 58
route/tool/set_mark/namumark.py

@@ -24,7 +24,7 @@ def link_fix(main_link):
 
     return [main_link, other_link]
 
-def table_parser(data, cel_data, start_data, num = 0):
+def table_parser(data, cel_data, cel_num, start_data, num = 0, cel_color = {}):
     table_class = 'class="'
     div_style = 'style="'
     all_table = 'style="'
@@ -33,6 +33,11 @@ def table_parser(data, cel_data, start_data, num = 0):
     row = ''
     cel = 'colspan="' + str(round(len(start_data) / 2)) + '"'
 
+    if not cel_num in cel_color:
+        cel_color[cel_num] = ''
+
+    cel_style += cel_color[cel_num]
+
     if num == 0:
         if re.search('^ ', cel_data) and re.search(' $', cel_data):
             cel_style += 'text-align: center;'
@@ -95,8 +100,19 @@ def table_parser(data, cel_data, start_data, num = 0):
         elif re.search("^table ?color=([^=]+)$", in_state):
             table_data = re.sub('^table ?color=', '', in_state)
             all_table += 'color: ' + (re.sub(',([^,]*)', '', table_data) if re.search(',', table_data) else table_data) + ';'
+        elif re.search("^col ?bgcolor=([^=]+)$", in_state):
+            table_data = re.sub('^col ?bgcolor=', '', in_state)
+            table_data = (re.sub(',([^,]*)', '', table_data) if re.search(',', table_data) else table_data)
+            cel_color[cel_num] += 'background: ' + table_data + ';'
+            cel_style += 'background: ' + table_data + ';'
+        elif re.search("^col ?color=([^=]+)$", in_state):
+            table_data = re.sub('^col ?color=', '', in_state)
+            table_data = (re.sub(',([^,]*)', '', table_data) if re.search(',', table_data) else table_data)
+            cel_color[cel_num] += 'color: ' + table_data + ';'
+            cel_style += 'color: ' + table_data + ';'
         elif re.search("^(bgcolor=([^=]+)|#(?:[0-9a-f-A-F]{3}){1,2}|\w+)$", in_state):
-            cel_style += 'background: ' + re.sub('^bgcolor=', '', in_state) + ';'
+            table_data = re.sub('^bgcolor=', '', in_state)
+            cel_style += 'background: ' + (re.sub(',([^,]*)', '', table_data) if re.search(',', table_data) else table_data) + ';'
         elif re.search("^color=([^=]+)$", in_state):
             table_data = re.sub('^color=', '', in_state)
             cel_style += 'color: ' + (re.sub(',([^,]*)', '', table_data) if re.search(',', table_data) else table_data) + ';'
@@ -122,72 +138,81 @@ def table_parser(data, cel_data, start_data, num = 0):
     row_style += '"'
     table_class += '"'
 
-    return [all_table, row_style, cel_style, row, cel, table_class, num, div_style]
+    return [all_table, row_style, cel_style, row, cel, table_class, num, div_style, cel_color]
 
 def table_start(data):
+    cel_num = 0
+    table_num = 0
+    table_end = ''
     while 1:
         table = re.search('\n((?:(?:(?:(?:\|\||\|[^|]+\|)+(?:(?:(?!\|\|).\n*)*))+)\|\|(?:\n)?)+)', data)
         if table:
-            table = table.groups()[0]
-
-            all_table = re.search('^((?:\|\||\|[^|]+\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*((?:(?!\|\|).\n*)*)', table)
-            if all_table:
-                all_table = all_table.groups()
-
-                return_table = table_parser(all_table[1], all_table[2], re.sub('^\|([^|]+)\|', '||', all_table[0]))
-                number = return_table[6]
-
-                table_caption = re.search('^\|([^|]+)\|', table)
-                table_caption = '<caption>' + table_caption.groups()[0] + '</caption>' if table_caption else ''
-
-                table = re.sub(
-                    '^((?:\|\||\|[^|]+\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*',
-                    '\n' + \
-                        '<div class="table_safe" ' + return_table[7] + '>' + \
-                            '<table ' + return_table[5] + ' ' + return_table[0] + '>' + \
-                                table_caption + \
-                                '<tbody>' + \
-                                    '<tr ' + return_table[1] + '>' + \
-                                        '<td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>',
-                    table,
-                    1
-                )
-
-            table = re.sub('\|\|\n?$', '</td></tr></tbody></table></div>', table)
-
-            while 1:
-                row_table = re.search('\|\|\n((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*((?:(?!\|\||<\/td>).\n*)*)', 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(
-                        '\|\|\n((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*',
-                        '</td></tr><tr ' + return_table[1] + '><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>',
-                        table,
-                        1
+            table = '\n' + table.groups()[0]
+            table_cel = re.findall('(\n(?:(?:\|\|)+)|\|\|\n(?:(?:\|\|)+)|(?:(?:\|\|)+))((?:(?:(?!\n|\|\|).)+\n*)+)', table)
+            for i in table_cel:
+                cel_plus = re.search('^((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)', i[1])
+                cel_plus = cel_plus.groups()[0] if cel_plus else ''
+                cel_data = re.sub('^((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)', '', i[1])
+
+                if re.search('^\n', i[0]):
+                    cel_num = 1
+
+                    cel_plus = table_parser(
+                        cel_plus, 
+                        cel_data,
+                        cel_num,
+                        re.sub('^\n', '', i[0])
                     )
+                    cel_color = cel_plus[8]
+                    table_num = cel_plus[6]
+
+                    table_end += '' + \
+                        '<div class="table_safe" ' + cel_plus[7] + '>' + \
+                            '<table ' + cel_plus[5] + ' ' + cel_plus[0] + '>' + \
+                                '<tr ' + cel_plus[1] + '>' + \
+                                    '<td ' + cel_plus[2] + ' ' + cel_plus[3] + ' ' + cel_plus[4] + '>' + \
+                                        cel_data
+                                        
+                elif re.search('\n', i[0]):
+                    cel_num = 1
+
+                    cel_plus = table_parser(
+                        cel_plus, 
+                        cel_data,
+                        cel_num,
+                        re.sub('^\|\|\n', '', i[0]),
+                        table_num,
+                        cel_color
+                    )
+                    cel_color = cel_plus[8]
+
+                    table_end += '' + \
+                            '</td>' + \
+                        '</tr>' + \
+                        '<tr ' + cel_plus[1] + '>' + \
+                            '<td ' + cel_plus[2] + ' ' + cel_plus[3] + ' ' + cel_plus[4] + '>' + \
+                                cel_data
                 else:
-                    break
-
-            while 1:
-                cel_table = re.search('((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*((?:(?:(?!\|\||<\/td>).)|\n)*\n*)', table)
-                if cel_table:
-                    cel_table = cel_table.groups()
+                    cel_num += 1
+
+                    cel_plus = table_parser(
+                        cel_plus, 
+                        cel_data,
+                        cel_num,
+                        re.sub('^\|\|\n', '', i[0]),
+                        table_num,
+                        cel_color
+                    )
+                    cel_color = cel_plus[8]
 
-                    return_table = table_parser(cel_table[1], re.sub('\n', ' ', cel_table[2]), cel_table[0], number)
+                    table_end += '' + \
+                        '</td>' + \
+                        '<td ' + cel_plus[2] + ' ' + cel_plus[3] + ' ' + cel_plus[4] + '>' + \
+                            cel_data
 
-                    table = re.sub(
-                        '((?:\|\|)+)((?:&lt;(?:(?:(?!&gt;).)+)&gt;)*)\n*',
-                        '</td><td ' + return_table[2] + ' ' + return_table[3] + ' ' + return_table[4] + '>',
-                        table,
-                        1
-                    )
-                else:
-                    break
+            table_end += '</td></tr></table>'
 
-            data = re.sub('\n((?:(?:(?:(?:\|\||\|[^|]+\|)+(?:(?:(?!\|\|).\n*)*))+)\|\|(?:\n)?)+)', table, data, 1)
+            data = re.sub('\n((?:(?:(?:(?:\|\||\|[^|]+\|)+(?:(?:(?!\|\|).\n*)*))+)\|\|(?:\n)?)+)', table_end, data, 1)
         else:
             break
 

+ 6 - 6
route/topic_tool.py

@@ -10,13 +10,13 @@ def topic_tool_2(conn, topic_num):
     close_data = curs.fetchall()
     if close_data:
         if close_data[0][0] == 'S':
-            t_state = 'stop'
+            t_state = 'Stop'
         elif close_data[0][0] == 'O':
-            t_state = 'close'
+            t_state = 'Close'
         else:
-            t_state = 'normal'
+            t_state = 'Normal'
     else:
-        t_state = 'normal'
+        t_state = 'Normal'
 
     curs.execute(db_change("select acl from rd where code = ?"), [topic_num])
     topic_acl_get = curs.fetchall()
@@ -33,8 +33,8 @@ def topic_tool_2(conn, topic_num):
         <h2>''' + load_lang('tool') + '''</h2>
         <ul>
             <li><a id="reload" href="javascript:void(0);" onclick="req_alarm();">''' + load_lang('use_push_alarm') + '''</a></li>
-            <li>''' + load_lang('topic_state') + ''' : ''' + t_state + '' + (' (agree)' if close_data and (close_data[0][1] == 'O') else '') + '''</li>
-            <li>''' + load_lang('topic_acl') + ''' : <a href="/acl/TEST#exp">''' + ('normal' if not topic_acl_get or (topic_acl_get[0][0] == '') else topic_acl_get[0][0]) + '''</a></li>
+            <li>''' + load_lang('topic_state') + ''' : ''' + t_state + '' + (' (Agree)' if close_data and (close_data[0][1] == 'O') else '') + '''</li>
+            <li>''' + load_lang('topic_acl') + ''' : <a href="/acl/TEST#exp">''' + ('Normal' if not topic_acl_get or (topic_acl_get[0][0] == '') else topic_acl_get[0][0]) + '''</a></li>
         </ul>
     '''
 

+ 2 - 2
version.json

@@ -1,7 +1,7 @@
 {
     "master" : {
-        "r_ver" : "v3.1.7-master-10",
-        "c_ver" : "3170801",
+        "r_ver" : "v3.1.7-master-11",
+        "c_ver" : "3171100",
         "s_ver" : "7"
     }, "stable" : {
         "r_ver" : "v3.1.6-stable-05",