返回顶部
f

feishu-doc-writer飞书文档写入器

Feishu (Lark) Document API writing spec. Converts Markdown content to Feishu Block structures and writes to cloud docs. Handles concurrency ordering. Use when syncing articles, creating document blocks, or writing long-form content to Feishu docs.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
873
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

feishu-doc-writer

飞书文档写入器

通过 Docx API 向飞书云文档写入内容的参考规范。飞书文档采用块树模型——不支持原始 Markdown。

文档(block_type=1, Page)
+-- 标题1块(block_type=3)
+-- 文本块(block_type=2)
+-- 高亮块(block_type=19)
| +-- 文本块
| +-- 无序列表块
+-- 图片块(block_type=27)
+-- 分割线块(block_type=22)

推荐方案:转换接口

飞书提供了官方的 Markdown -> 块 转换接口:

POST /open-apis/docx/v1/documents/{document_id}/convert

json
{
content: # 标题\n\n正文内容\n\n- 项目1\n- 项目2\n\n> 引用,
content_type: markdown
}

优点:无需手动构建块 JSON。支持大多数标准 Markdown。
限制:不支持飞书特有的块(如高亮块等)——这些需要使用手动创建块的方式。

块类型参考

block_type名称JSON 键说明
1页面page文档根节点
2
文本 | text | 段落 | | 3-11 | 标题1-9 | heading1-heading9 | 标题 | | 12 | 无序列表 | bullet | 无序列表(每个项目为独立块) | | 13 | 有序列表 | ordered | 有序列表 | | 14 | 代码 | code | 代码块(含 style.language 枚举) | | 15 | 引用 | quote | 块引用 | | 17 | 待办 | todo | 复选框项目(含 style.done) | | 19 | 高亮块 | callout | 高亮框(飞书特有,容器块) | | 22 | 分割线 | divider | 水平分割线 | | 27 | 图片 | image | 两步操作:先创建占位,再上传 | | 31 | 表格 | table | 表格 | | 34 | 引用容器 | quote_container | 引用容器 |

创建块接口

POST /open-apis/docx/v1/documents/{documentid}/blocks/{blockid}/children?documentrevisionid=-1

请求头:
Content-Type: application/json
Authorization: Bearer access
token>

请求体:
{
children: [ ...块数组... ],
index: 0
}

  • - blockid:父块 ID(根节点通常为 documentid 本身)
  • index:插入位置(0 = 开头,-1 或省略 = 末尾)

块 JSON 示例

文本

json
{
block_type: 2,
text: {
elements: [{
text_run: {
content: 此处为段落文本,
textelementstyle: { bold: false, italic: false }
}
}]
}
}

标题

json
{ blocktype: 3, heading1: { elements: [{ textrun: { content: H1 标题 } }] } }
{ blocktype: 4, heading2: { elements: [{ textrun: { content: H2 标题 } }] } }

无序列表 / 有序列表

json
{ blocktype: 12, bullet: { elements: [{ textrun: { content: 列表项目 } }] } }
{ blocktype: 13, ordered: { elements: [{ textrun: { content: 编号项目 } }] } }

每个列表项是一个独立的块

代码块

json
{
block_type: 14,
code: {
elements: [{ text_run: { content: console.log(hello); } }],
style: { language: 23, wrap: false }
}
}

常用语言枚举:纯文本=1, JavaScript=23, Python=40, TypeScript=49, Go=20, Shell=46, SQL=47, Java=22, Rust=44, C=12, CSS=17, HTML=21, Docker=19。

高亮块(飞书特有的高亮框)

高亮块是一个容器块——先创建它,然后在内部添加子块。

json
// 步骤1:创建高亮块作为文档子块
{ blocktype: 19, callout: { backgroundcolor: 3, bordercolor: 3, emojiid: star } }

// 步骤2:POST .../blocks/{calloutblockid}/children
{ children: [{ blocktype: 2, text: { elements: [{ textrun: { content: 高亮文本 } }] } }] }

颜色枚举:红色=1, 橙色=2, 黄色=3, 绿色=4, 蓝色=5, 紫色=6, 灰色=7。

分割线

json
{ block_type: 22, divider: {} }

图片(两步操作)

步骤1:创建占位块 { block_type: 27, image: {} }
步骤2:通过 POST /open-apis/drive/v1/medias/upload_all 上传
- multipart/form-data: file, filename, parenttype=docximage, parentnode=blockid>

文本样式

通过 textrun 中的 textelement_style 应用样式:

属性类型效果
bold布尔值加粗
italic
布尔值 | 斜体 |
| strikethrough | 布尔值 | 删除线 |
| underline | 布尔值 | 下划线 |
| inline_code | 布尔值 | 行内代码 |
| text_color | 整数 | 文本颜色(与高亮块颜色枚举相同) |
| background_color | 整数 | 背景颜色 |
| link.url | 字符串 | 超链接 |

一个块中包含多个 text_run 元素 = 同一段落中的混合样式。

Markdown 到块的映射

Markdownblock_typeJSON 键
# H13heading1
## H2
4 | heading2 | | ### H3 | 5 | heading3 | | 段落 | 2 | text | | - 项目 | 12 | bullet | | 1. 项目 | 13 | ordered | | 代码围栏 | 14 | code | | > 引用 | 15 | quote | | - [ ] 待办 | 17 | todo | | --- | 22 | divider | | url | 27 | image(两步操作) | | 加粗 | -- | textelementstyle.bold: true | | 斜体 | -- | textelementstyle.italic: true | | 代码 | -- | textelementstyle.inline_code: true | | ~~删除~~ | -- | textelementstyle.strikethrough: true | | 文本 | -- | textelement_style.link.url | | (无 MD 等价物) | 19 | callout(飞书特有) |

并发与排序(关键)

问题:并发创建块的 API 调用会产生随机排序。

方案 A:单次批量请求(推荐)

将所有块放在一个 children 数组中,单次 API 调用:

json
{
children: [
{ blocktype: 3, heading1: { elements: [{textrun: {content: 标题}}] } },
{ blocktype: 2, text: { elements: [{textrun: {content: 段落1}}] } },
{ block_type: 22, divider: {} },
{ blocktype: 4, heading2: { elements: [{textrun: {content: 章节2}}] } }
],
index: 0
}

方案 B:带索引的串行写入

对于需要多次请求的长内容

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 feishu-doc-write-1776420033 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 feishu-doc-write-1776420033 技能

通过命令行安装

skillhub install feishu-doc-write-1776420033

下载

⬇ 下载 feishu-doc-writer v1.0.0(免费)

文件大小: 4.29 KB | 发布时间: 2026-4-17 18:51

v1.0.0 最新 2026-4-17 18:51
- Initial release of feishu-doc-writer, providing a comprehensive spec for converting Markdown to Feishu (Lark) cloud document blocks.
- Supports Feishu's Block tree model, including headings, text, lists, code, quotes, todos, dividers, images, tables, and Feishu-specific Callout blocks.
- Details the official Markdown-to-Blocks conversion endpoint for streamlined document creation.
- Includes extensive Block type references with JSON examples for all major block types.
- Explains concurrency and block ordering pitfalls with recommended batch writing solutions.
- Documents custom Callout markup syntax for enhanced content formatting.
- Provides text styling options and Markdown-to-Block mapping for feature-rich document output.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部