From e6b0e9293c3c0e6cb353613a3b7a952cfb9361b5 Mon Sep 17 00:00:00 2001 From: karuo Date: Wed, 25 Feb 2026 12:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20=E5=8D=A1=E8=8B=A5AI=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=202026-02-25=2012:11=20|=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=9A=E6=B0=B4=E6=A1=A5=E5=B9=B3=E5=8F=B0=E5=AF=B9=E6=8E=A5?= =?UTF-8?q?=E3=80=81=E8=BF=90=E8=90=A5=E4=B8=AD=E6=9E=A2=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8F=B0=20|=20=E6=8E=92=E9=99=A4=20>20MB:=2013=20=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../飞书管理/脚本/md_to_feishu_json.py | 77 ++++++++++++++++++- 运营中枢/工作台/gitea_push_log.md | 1 + 运营中枢/工作台/代码管理.md | 1 + 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/02_卡人(水)/水桥_平台对接/飞书管理/脚本/md_to_feishu_json.py b/02_卡人(水)/水桥_平台对接/飞书管理/脚本/md_to_feishu_json.py index b30bec95..c533b1a0 100644 --- a/02_卡人(水)/水桥_平台对接/飞书管理/脚本/md_to_feishu_json.py +++ b/02_卡人(水)/水桥_平台对接/飞书管理/脚本/md_to_feishu_json.py @@ -35,6 +35,39 @@ def _image_placeholder(idx: int, path: str) -> dict: return {"__image__": path, "__index__": idx} +def _sheet_table(values: list[list[str]]) -> dict: + rows = len(values) + cols = max((len(r) for r in values), default=0) + return { + "block_type": 30, + "sheet": {"row_size": rows, "column_size": cols}, + "__sheet_values": values, + } + + +def _parse_md_row(line: str) -> list[str]: + s = line.strip() + if s.startswith("|"): + s = s[1:] + if s.endswith("|"): + s = s[:-1] + return [c.strip() for c in s.split("|")] + + +def _is_md_table_sep(line: str) -> bool: + s = line.strip() + if not s: + return False + if s.startswith("|"): + s = s[1:] + if s.endswith("|"): + s = s[:-1] + parts = [p.strip() for p in s.split("|")] + if not parts: + return False + return all(re.match(r"^:?-{3,}:?$", p or "") for p in parts) + + def _clean_inline_markdown(text: str) -> str: """清理常见行内 markdown 标记,输出更适合飞书阅读的纯文本。""" t = text @@ -57,7 +90,10 @@ def md_to_blocks(md: str, image_paths: list[str] | None = None) -> list: in_code = False code_lines = [] - for line in md.split("\n"): + lines = md.split("\n") + i = 0 + while i < len(lines): + line = lines[i] if line.strip().startswith("```"): if in_code: # 飞书 blocks 常对代码围栏/特殊格式更严格,这里转为普通文本行,提升美观与稳定性 @@ -66,9 +102,11 @@ def md_to_blocks(md: str, image_paths: list[str] | None = None) -> list: blocks.append(_text(f"代码:{cl.strip()}")) code_lines = [] in_code = not in_code + i += 1 continue if in_code: code_lines.append(line) + i += 1 continue # 图片语法 ![](path) @@ -79,10 +117,45 @@ def md_to_blocks(md: str, image_paths: list[str] | None = None) -> list: path = image_paths[img_idx] blocks.append(_image_placeholder(img_idx, path)) img_idx += 1 + i += 1 + continue + + # Markdown 表格:表头 + 分隔行 + 数据行 + if "|" in line and i + 1 < len(lines) and _is_md_table_sep(lines[i + 1]): + table_lines = [line] + j = i + 2 + while j < len(lines): + raw = lines[j].strip() + if not raw or "|" not in raw: + break + if raw.startswith("#") or raw.startswith(">") or raw.startswith("```"): + break + table_lines.append(lines[j]) + j += 1 + + rows = [_parse_md_row(x) for x in table_lines] + col_size = max((len(r) for r in rows), default=0) + if col_size > 0: + clean_rows: list[list[str]] = [] + for r in rows: + rr = [_clean_inline_markdown(c) for c in r] + if len(rr) < col_size: + rr.extend([""] * (col_size - len(rr))) + clean_rows.append(rr[:col_size]) + + # 飞书空 sheet 创建限制:行列最大 9,超出时截断并提示 + max_rows, max_cols = 9, 9 + if len(clean_rows) > max_rows or col_size > max_cols: + blocks.append(_text("提示:原表格超出飞书单块上限,已自动截断为 9x9。")) + clipped = [r[:max_cols] for r in clean_rows[:max_rows]] + blocks.append(_sheet_table(clipped)) + + i = j continue # 忽略 Markdown 水平分隔线(避免在飞书出现大量“---”影响观感) if line.strip() in {"---", "***", "___"}: + i += 1 continue # 标题 @@ -115,6 +188,8 @@ def md_to_blocks(md: str, image_paths: list[str] | None = None) -> list: if cleaned: blocks.append(_text(cleaned)) + i += 1 + return blocks diff --git a/运营中枢/工作台/gitea_push_log.md b/运营中枢/工作台/gitea_push_log.md index 8e94d0ae..acd7ce2f 100644 --- a/运营中枢/工作台/gitea_push_log.md +++ b/运营中枢/工作台/gitea_push_log.md @@ -141,3 +141,4 @@ | 2026-02-25 11:03:16 | 🔄 卡若AI 同步 2026-02-25 11:03 | 更新:水桥平台对接、运营中枢工作台 | 排除 >20MB: 13 个 | | 2026-02-25 11:52:39 | 🔄 卡若AI 同步 2026-02-25 11:52 | 更新:水溪整理归档、运营中枢、运营中枢工作台 | 排除 >20MB: 13 个 | | 2026-02-25 12:07:57 | 🔄 卡若AI 同步 2026-02-25 12:07 | 更新:Cursor规则、水桥平台对接、运营中枢、运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 13 个 | +| 2026-02-25 12:09:29 | 🔄 卡若AI 同步 2026-02-25 12:09 | 更新:运营中枢、运营中枢工作台 | 排除 >20MB: 13 个 | diff --git a/运营中枢/工作台/代码管理.md b/运营中枢/工作台/代码管理.md index 466051be..2ea75d14 100644 --- a/运营中枢/工作台/代码管理.md +++ b/运营中枢/工作台/代码管理.md @@ -144,3 +144,4 @@ | 2026-02-25 11:03:16 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-25 11:03 | 更新:水桥平台对接、运营中枢工作台 | 排除 >20MB: 13 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-02-25 11:52:39 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-25 11:52 | 更新:水溪整理归档、运营中枢、运营中枢工作台 | 排除 >20MB: 13 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | | 2026-02-25 12:07:57 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-25 12:07 | 更新:Cursor规则、水桥平台对接、运营中枢、运营中枢参考资料、运营中枢工作台 | 排除 >20MB: 13 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) | +| 2026-02-25 12:09:29 | 成功 | 成功 | 🔄 卡若AI 同步 2026-02-25 12:09 | 更新:运营中枢、运营中枢工作台 | 排除 >20MB: 13 个 | [仓库](http://open.quwanzhi.com:3000/fnvtk/karuo-ai) [百科](http://open.quwanzhi.com:3000/fnvtk/karuo-ai/wiki) |