feishu-doc-export
Latest: v1.0.0
Auto-publish from commit 4019dfd6f61f55bd9ace0bded470f28711aa0a6b
feishu-doc-export — 飞书文档导出
语言规则
检测用户使用的语言,全程使用同一语言输出。
中文版
核心用途
官方 SDK(feishu-doc 技能依赖 feishu-common)与浏览器面板在本机都跑不通时的直连路径:用应用凭证换 tenant_access_token,直接调 docx Open API 把文档导出为 Markdown / 纯文本。已在一篇含 callout、表格、多级标题、代码块的真实接口文档上实测(569 blocks 全量无丢失)。
适用场景与触发条件
- 用户给一个飞书文档/wiki 链接或 token,要求读取、导出或转 Markdown;
- 本地 feishu-doc 技能不可用(缺依赖)或浏览器无登录态时。
前置条件(缺了就停,如实说明):应用凭证 FEISHU_APP_ID / FEISHU_APP_SECRET(环境变量或 --env-file 的 KEY=VALUE 文件,支持 export KEY= 前缀)。文档必须对该应用可见——403/99991672 时请文档所有者把应用加为协作者,不要重试。
执行步骤
python3 scripts/feishu_export.py title <token> --env-file <凭证文件>先确认可见性。python3 scripts/feishu_export.py markdown <token> -o out.md --env-file <凭证文件>导出 Markdown;raw子命令出纯文本预览。- wiki 链接先给节点 token,脚本会自动
get_node解析出 obj_token(仅支持 docx 类型)。
输出
Markdown 文件:H1 文档标题 + 标题树(块类型 3–11 映射 #–########)、无序/有序/待办列表、引用与 callout(转 blockquote)、代码块(语言映射表,28=JSON 等)、表格(table.cells 行主序组装,首个行为表头)、行内加粗/斜体/行内码/链接;图片输出 feishu-image:<token> 占位(不下载)。
异常处理与限制
- 权限不足、obj_type 非 docx(如 sheet)时明确报错退出,不猜。
- 脚本只读:只调 token / get_node / documents / blocks 只读接口,不写文档。
- 已知边界:图片只给占位链接; bitable/board 等非 docx 块类型按兜底文本处理;富文本中的 @提及、表情按纯文本落下。
验收标准
- 对一篇真实文档导出的 Markdown:标题层级完整、表格为合法 Markdown 管道表、无重复段落、无空标题。
English
Purpose
Direct Open API export of Feishu docx (incl. wiki node resolution) to Markdown/plain text — no SDK, no browser session. Verified on a real 569-block doc containing callouts, tables, headings and code blocks.
Steps
title → visibility check; markdown → full export (-o out.md); raw → plain preview. Wiki tokens auto-resolve via get_node (docx only). Requires FEISHU_APP_ID / FEISHU_APP_SECRET via env or --env-file (supports export KEY= lines). On 403/99991672 stop and ask the doc owner to add the app as collaborator — do not retry.
Read-only: token / get_node / documents / blocks GET endpoints only.
