From 53e53fc20c942e788f55315a75e2b436a4468fcc Mon Sep 17 00:00:00 2001 From: NightStar Date: Wed, 19 Aug 2026 14:47:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A3=9E=E4=B9=A6=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93=E8=AF=BB=E5=86=99=E5=B7=A5=E5=85=B7=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=9F=A5=E6=94=B9=E8=8A=82=E7=82=B9=E3=80=81=E5=86=99?= =?UTF-8?q?=E5=85=A5=E9=A1=B5=E9=9D=A2=E3=80=81=E5=88=9B=E5=BB=BA=E6=97=A9?= =?UTF-8?q?=E6=8A=A5=E3=80=81=E8=AE=B0=E5=BD=95=E8=B8=A9=E5=9D=91=EF=BC=8C?= =?UTF-8?q?=E5=9F=BA=E4=BA=8E=20tenant=5Faccess=5Ftoken=EF=BC=88=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=A1=A8=E6=A0=BC=E5=86=99=E5=85=A5=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?+=E8=A1=A8=E5=A4=B4=E4=B8=A2=E5=A4=B1+ID=E5=86=B2=E7=AA=81?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/md_to_blocks.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/md_to_blocks.py b/scripts/md_to_blocks.py index 5d66091..7f177c4 100644 --- a/scripts/md_to_blocks.py +++ b/scripts/md_to_blocks.py @@ -15,6 +15,9 @@ TEXT_BLOCK = 2 CODE_BLOCK = 14 PREFIX = 'ecc_' +# 全局表格计数器:每个表格用唯一 ID 前缀,避免多表格时 block_id 冲突 +_table_counter = 0 + LANG_CODES = { '': 1, 'text': 1, 'plain': 1, 'bash': 7, 'sh': 7, 'shell': 7, @@ -87,6 +90,7 @@ def split_row(line): def parse_table(lines, start_idx): """Parse a markdown table. Returns (blocks, end_idx) or (None, start_idx).""" + global _table_counter i = start_idx headers = [] has_header = False @@ -115,8 +119,10 @@ def parse_table(lines, start_idx): data_rows.append(row) i += 1 - # No header case: first line was a data row - if not has_header: + # 表头行必须作为第一行保留(飞书 header_row=True 时首行即表头) + if has_header: + data_rows.insert(0, headers) + else: data_rows.insert(0, first_cells) if not data_rows: @@ -127,7 +133,8 @@ def parse_table(lines, start_idx): # Build nested blocks blocks = [] - table_id = f'{PREFIX}t0' + table_id = f'{PREFIX}t{_table_counter}' + _table_counter += 1 cell_ids = [] # Table container @@ -150,8 +157,8 @@ def parse_table(lines, start_idx): for row_idx, row in enumerate(data_rows): for col_idx in range(num_cols): cell_text = row[col_idx] if col_idx < len(row) else '' - cell_id = f'{PREFIX}t0r{row_idx}c{col_idx}' - text_id = f'{PREFIX}t0r{row_idx}c{col_idx}t' + cell_id = f'{table_id}r{row_idx}c{col_idx}' + text_id = f'{table_id}r{row_idx}c{col_idx}t' cell_ids.append(cell_id) is_header_cell = has_header and row_idx == 0