Przeglądaj źródła

转html时避免重复加入td

liweiquan 11 miesięcy temu
rodzic
commit
3729bbe1ac
3 zmienionych plików z 10 dodań i 13 usunięć
  1. 0 2
      cores/post_decorators.py
  2. 10 10
      cores/post_hander.py
  3. 0 1
      server.py

+ 0 - 2
cores/post_decorators.py

@@ -125,7 +125,6 @@ def rule7_decorator(f, *args, **kwargs):
     predict_line = ['项目 ', '', '每份(70g)营养素参考值%', '']
     '''
     predict_line = f(*args, **kwargs)
-    print('-=-=', predict_line)
     try:
         if '项目' in predict_line[0] or '项' in predict_line[0] or '目' in predict_line[0]:
             predict_line[0] = '项目'
@@ -139,7 +138,6 @@ def rule8_decorator(f, *args, **kwargs):
     predict_line = ['项目 ', '', '每份(70g)营养素参考值%', '']
     '''
     predict_line = f(*args, **kwargs)
-    print('-=-=', predict_line)
     try:
         if len(predict_line) >= 3 \
                 and '' == predict_line[0] \

+ 10 - 10
cores/post_hander.py

@@ -15,24 +15,24 @@ class PostHandler:
             COLS = 3
             html = []
             for i, line in enumerate(self.format_lines):
+                print('-=-=-=-=', line)
                 html.append('<tr>')
                 for j in range(COLS):
+                    col_html = []
                     try:
                         if i == 0 and '成分表' in line[j]:
-                            html.append('<td colspan="3">')
-                            html.append(line[j])
-                            html.append('</td>')
+                            col_html.append('<td colspan="3">')
+                            col_html.append(line[j])
+                            col_html.append('</td>')
                             break
                         else:
-                            html.append('<td>')
-                            html.append(line[j])
-                            html.append('</td>')
+                            col_html.append('<td>')
+                            col_html.append(line[j])
+                            col_html.append('</td>')
                     except IndexError as e:
                         print(e)
-                        html.append('<td>')
-                        html.append('')
-                        html.append('</td>')
-                        continue
+                        col_html = ['<td>', '', '</td>']
+                    html.extend(col_html)
                 html.append('</tr>')
             res = f'{header}{"".join(html)}{footer}'
             return res

+ 0 - 1
server.py

@@ -178,7 +178,6 @@ def table(image: TableInfo):
     # print(html)
     table = Table(html, img)
     if table.check_html():
-        print('-=-=-=')
         res, html = table_res(table.img)
 
     if html: