关于Adaptive Card手动编号自动重排致文本编号不匹配的技术问询
Adaptive Card纯文本手动编号被自动重排的问题解决
问题描述
在Adaptive Card的TextBlock字段中使用纯文本手动编号(如1. 第一点)添加要点时,若编号顺序打乱(比如1. First point\n3. Third point\n2. Second point),渲染后编号会被自动重排为1、2、3,但文本内容保持原顺序,导致编号和对应内容不匹配。
示例
输入文本:
1. First point 3. Third point 2. Second point
渲染输出:
1. First point 2. Third point 3. Second point
问题表现:
- 编号被自动标准化重排
- 文本内容未同步调整
复现环境
- Microsoft Teams(Actionable Messages / Adaptive Cards)
- Adaptive Card Designer
- 编号为纯文本一部分(未使用Adaptive Card的结构化列表组件)
预期与实际行为
- 预期:编号完全与输入文本一致
- 实际:渲染器自动重排编号,文本顺序不变
简化示例JSON
{ "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "text": "1. First point\n3. Third point\n2. Second point", "wrap": true } ], "version": "1.6" }
解决方案
1. 使用Adaptive Card结构化列表组件替代纯文本编号
改用Adaptive Card原生组件构建列表,确保编号与内容绑定,避免渲染器自动修改:
- 用
ColumnSet拆分编号与内容:
{ "type": "AdaptiveCard", "body": [ { "type": "ColumnSet", "columns": [ {"type": "Column", "width": "auto", "items": [{"type": "TextBlock", "text": "1."}]}, {"type": "Column", "width": "stretch", "items": [{"type": "TextBlock", "text": "First point", "wrap": true}]} ] }, { "type": "ColumnSet", "columns": [ {"type": "Column", "width": "auto", "items": [{"type": "TextBlock", "text": "3."}]}, {"type": "Column", "width": "stretch", "items": [{"type": "TextBlock", "text": "Third point", "wrap": true}]} ] }, { "type": "ColumnSet", "columns": [ {"type": "Column", "width": "auto", "items": [{"type": "TextBlock", "text": "2."}]}, {"type": "Column", "width": "stretch", "items": [{"type": "TextBlock", "text": "Second point", "wrap": true}]} ] } ], "version": "1.6" }
- 短内容可使用
FactSet组件:
{ "type": "AdaptiveCard", "body": [ { "type": "FactSet", "facts": [ {"title": "1.", "value": "First point"}, {"title": "3.", "value": "Third point"}, {"title": "2.", "value": "Second point"} ] } ], "version": "1.6" }
2. 修改纯文本编号格式,规避自动重排
调整编号写法,让渲染器不识别为自动列表:
- 替换点号为顿号:
1、First point\n3、Third point\n2、Second point - 用括号包裹编号:
(1) First point\n(3) Third point\n(2) Second point - 在数字与点号间加空格:
1 . First point\n3 . Third point\n2 . Second point - 使用全角点号:
1.First point\n3.Third point\n2.Second point
3. 禁用TextBlock的Markdown解析
若TextBlock默认启用Markdown解析,可强制设置为纯文本渲染:
{ "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "text": "1. First point\n3. Third point\n2. Second point", "wrap": true, "markdown": false } ], "version": "1.6" }
注意:禁用Markdown后,原有的Markdown格式(如加粗、链接)会失效,需根据需求选择。
内容的提问来源于stack exchange,提问作者Karthik
相关产品推荐
相关产品推荐

