如何使用Slack rich_text块实现嵌套项目符号列表
使用Slack
rich_text 块原生实现嵌套项目符号列表 嵌套项目符号列表不需要特殊兼容,直接在父级列表项内嵌套子rich_text_list即可,核心是遵守块的结构和参数规则,就能通过Block Kit Builder校验。
- 基础参数规则
- 所有项目符号列表的
style字段统一设为bullet - 顶层列表
indent参数值为0,每向下嵌套一层,子列表的indent值在父级基础上加1,不能跳级设置 - 子列表直接放在父级
rich_text_list的elements数组中,和承载文本内容的rich_text_section块同级,不要把列表嵌套进rich_text_section内部
- 所有项目符号列表的
- 可用的请求体结构示例
{ "channel": "你的目标频道ID", "blocks": [ { "type": "rich_text", "elements": [ { "type": "rich_text_list", "style": "bullet", "indent": 0, "elements": [ { "type": "rich_text_section", "elements": [ {"type": "text", "text": "一级列表第一项"} ] }, { "type": "rich_text_list", "style": "bullet", "indent": 1, "elements": [ { "type": "rich_text_section", "elements": [{"type": "text", "text": "二级嵌套第一项"}] }, { "type": "rich_text_section", "elements": [{"type": "text", "text": "二级嵌套第二项"}] }, { "type": "rich_text_list", "style": "bullet", "indent": 2, "elements": [ { "type": "rich_text_section", "elements": [{"type": "text", "text": "三级嵌套项"}] } ] } ] }, { "type": "rich_text_section", "elements": [{"type": "text", "text": "一级列表第二项"}] } ] } ] } ] }
- 常见校验报错排查
- 嵌套层级不连续:比如父级
indent为0,子级直接设为2,会直接触发结构错误 - 嵌套位置错误:把
rich_text_list放在rich_text_section的elements数组内部,属于非法嵌套 - 样式不匹配:同一缩进层级的列表混用
bullet和ordered样式,会导致渲染异常
- 嵌套层级不连续:比如父级
上述结构为Slack原生支持的嵌套列表实现,不需要通过mrkdwn手动打空格模拟缩进,渲染效果和Slack客户端原生编辑的嵌套列表完全一致。
内容的提问来源于stack exchange,提问作者Tamino
相关产品推荐
相关产品推荐

