Browse Source

띄어쓰기로 테이블 내용 정렬

2DU 8 years ago
parent
commit
8b6fe2b17c
2 changed files with 33 additions and 18 deletions
  1. 9 4
      app.py
  2. 24 14
      set_mark/table.py

+ 9 - 4
app.py

@@ -1636,7 +1636,7 @@ def other():
                             '== 관리자 ==\r\n' + \
                             ' * [[wiki:manager/1|관리자 메뉴]]\r\n' + \
                             '== 버전 ==\r\n' + \
-                            '이 오픈나무는 [[https://github.com/2DU/openNAMU/blob/SQLite/version.md|' + r_ver + ']]판 입니다.', 0, 0, 0),
+                            ' * 이 오픈나무는 [[https://github.com/2DU/openNAMU/blob/SQLite/version.md|' + r_ver + ']]판 입니다.', 0, 0, 0),
         menu = 0
     )))
     
@@ -1891,7 +1891,12 @@ def topic_admin(name = None, sub = None, num = None):
     ban += '== 기타 도구 ==\r\n'
     ban += ' * [[wiki:/topic/' + url_pas(name) + '/sub/' + url_pas(sub) + '/raw/' + str(num) + '|원본]]\r\n'
     ban = ' * 작성 시간 : ' + data[0][2] + '\r\n' + ban
-    ban = ' * 작성인 : ' + data[0][1] + ' [[wiki:record/' + url_pas(data[0][1]) + '|(기록)]]\r\n' + ban
+
+    if(re.search('(\.|:)', data[0][1])):
+        ban = ' * 작성인 : ' + data[0][1] + ' [[wiki:record/' + url_pas(data[0][1]) + '|(기록)]]\r\n' + ban
+    else:
+        ban = ' * 작성인 : [[사용자:' + data[0][1] + '|' + data[0][1] + ']] [[wiki:record/' + url_pas(data[0][1]) + '|(기록)]]\r\n' + ban
+
     ban = '== 정보 ==\r\n' + ban
     ban = '[목차(없음)]\r\n' + ban
 
@@ -3205,8 +3210,8 @@ def user_info():
         imp = ['사용자 메뉴', wiki_set(conn, 1), custom_data, other2([0, 0])],
         data =  namumark(conn, '',  '[목차(없음)]\r\n' + \
                                     '== 상태 ==\r\n' + \
-                                    ip_user + '\r\n\r\n'
-                                    '권한 상태 : ' + acl + '\r\n' + \
+                                    ' * ' + ip_user + '\r\n'
+                                    ' * 권한 상태 : ' + acl + '\r\n' + \
                                     '== 로그인 ==\r\n' + \
                                     plus + '\r\n' + \
                                     ' * [[wiki:register|회원가입]]\r\n' + \

+ 24 - 14
set_mark/table.py

@@ -1,6 +1,6 @@
 import re
 
-def table_p(d, d2):
+def table_p(d, d2, d3, num = 0):
     table_class = 'class="'
     alltable = 'style="'
     celstyle = 'style="'
@@ -23,6 +23,7 @@ def table_p(d, d2):
             
     table_t_a = re.search("<table\s?textalign=((?:(?!>).)*)>", d)
     if(table_t_a):
+        num = 1
         if(table_t_a.groups()[0] == 'right'):
             alltable += 'text-align: right;'
         elif(table_t_a.groups()[0] == 'center'):
@@ -91,6 +92,13 @@ def table_p(d, d2):
         celstyle += 'text-align: center;'
     elif(text_left):
         celstyle += 'text-align: left;'
+    elif(num == 0):
+        if(re.search('^ (.*) $', d3)):
+            celstyle += 'text-align: center;'
+        elif(re.search('^ (.*)$', d3)):
+            celstyle += 'text-align: right;'
+        elif(re.search('^(.*) $', d3)):
+            celstyle += 'text-align: left;'
 
     text_class = re.search("<table\s?class=((?:(?!>).)+)>", d)
     if(text_class):
@@ -102,7 +110,7 @@ def table_p(d, d2):
     rowstyle += '"'
     table_class += '"'
 
-    return([alltable, rowstyle, celstyle, row, cel, table_class])
+    return([alltable, rowstyle, celstyle, row, cel, table_class, num])
 
 def table(data):
     data = re.sub("(?:\|\|\r\n)", "#table#<tablenobr>", data)
@@ -128,7 +136,7 @@ def table(data):
             results = m.groups()
             table = results[0]
             while(1):
-                a = re.search("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?", table)
+                a = re.search("^(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\|).)*)", table)
                 if(a):
                     row = ''
                     cel = ''
@@ -136,28 +144,30 @@ def table(data):
                     rowstyle = ''
                     alltable = ''
                     table_d = ''
+                    num = 0
 
                     result = a.groups()
                     if(result[1]):
-                        table_d = table_p(result[1], result[0])
+                        table_d = table_p(result[1], result[0], result[2])
                         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]
+                        num = table_d[6]
                             
-                        table = re.sub("^(\|\|(?:(?:\|\|)+)?)((?:&lt;(?:(?:(?!&gt;).)*)&gt;)+)?",   "<table " + table_class + " " + alltable + "><tbody><tr " + rowstyle + "><td " + cel + " " + row + " " + celstyle + ">", table, 1)
+                        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)
+                        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)
+                b = re.search("\|\|\r\n(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\|).)*)", table)
                 if(b):
                     row = ''
                     cel = ''
@@ -167,21 +177,21 @@ def table(data):
 
                     result = b.groups()
                     if(result[1]):
-                        table_d = table_p(result[1], result[0])
+                        table_d = table_p(result[1], result[0], result[2], num)
                         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)
+                        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)
+                        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)
+                c = re.search("(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)((?:(?!\|\|).)*)", table)
                 if(c):
                     row = ''
                     cel = ''
@@ -190,15 +200,15 @@ def table(data):
 
                     result = c.groups()
                     if(result[1]):
-                        table_d = table_p(result[1], result[0])
+                        table_d = table_p(result[1], result[0], result[2], num)
                         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)
+                        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)
+                        table = re.sub("(\|\|(?:(?:\|\|)*))((?:&lt;(?:(?:(?!&gt;).)*)&gt;)*)", "</td><td " + cel + ">", table, 1)
                 else:
                     break