跳到內容

<annotation> 注释元素

本頁內容尚未翻譯。

<annotation> 元素用于在正文中插入可展开查看详情的行内注释(例如术语解释、技能补充机制)。它以行内形态嵌入段落,内部通过 <title> 定义行内显示的触发文本,通过 <content> 承载完整的块级详情内容。

本页内容

本页说明以下三个关联元素:

  • <annotation>:行内注释容器,必须且只能包含一个 <title> 和一个 <content>,不可包含直接文本。
  • <title>:注释的行内显示文本,支持富文本样式、链接、注音与 <emoji>,可为空。
  • <content>:注释展开后的详情区域,支持段落、引用、列表、图片、视频、分隔线与表格等块级元素,可为空。

试一试

展开交互编辑器,修改 <title> 里的加粗文字或 <content> 里的引用块,查看 annotation.inlineElements 与 annotation.childIds 的生成结果。

試一試

属性

<annotation>、<title> 与 <content> 均不定义任何属性。

示例

以下示例展示带块级详情的注释、注释的嵌套禁止规则以及子元素缺失的反例。

包含块级详情的注释与规范化输出

注释的 <content> 内部换行独立处理,不会打断外层段落;外层段落中的 <annotation> 始终作为单个行内单元保留。

<?xml version="1.0" encoding="UTF-8"?>
<sklandDocument>
    <itemId>81</itemId>
    <metainfo>
        <name>完整注释示例</name>
        <cover/>
        <subTypes/>
    </metainfo>
    <description>
        前置文字<annotation><title>查看<color value="f_blue">详情</color></title><content>
            第一段说明。
            <ul>
                <li>要点一</li>
                <li>要点二</li>
            </ul>
        </content></annotation>后续文字。
    </description>
</sklandDocument>

渲染为 JSON 时,<content> 中的块存入所属文档的 blockMap,由注释对象的 childIds 引用,且直属块的 parentId 指向注释所在的段落块。

在注释内再次嵌套 <annotation>(错误写法)

无论在 <title> 还是 <content> 中,都不允许再次嵌套 <annotation>,即便中间隔了样式元素或表格也不允许。

<sklandDocument>
    <itemId>82</itemId>
    <metainfo>
        <name>嵌套注释</name>
        <cover/>
        <subTypes/>
    </metainfo>
    <description>
        <annotation>
            <title>外层<annotation><title>内层</title><content/></annotation></title>
            <content>说明</content>
        </annotation>
    </description>
</sklandDocument>

转换器抛出 XmlWikiConversionError: Nested annotations are not supported.。将内层注释拆为平级注释或改为普通文本即可修复。

在表格单元格的注释内嵌套 <table>(错误写法)

复杂表格单元格允许包含 <annotation>,但该注释的 <content> 继承了单元格禁止嵌套表格的约束。

<sklandDocument>
    <itemId>83</itemId>
    <metainfo>
        <name>表内注释含表格</name>
        <cover/>
        <subTypes/>
    </metainfo>
    <description>
        <table widths="200">
            <tr>
                <td>
                    <annotation>
                        <title>详情</title>
                        <content>
                            <table widths="100">
                                <tr><td>内层表格</td></tr>
                            </table>
                        </content>
                    </annotation>
                </td>
            </tr>
        </table>
    </description>
</sklandDocument>

转换器抛出 XmlWikiConversionError: Nested tables are not supported inside table cells.。将表格移至外层表格之外,或在注释 <content> 中改用列表呈现即可。

<annotation> 缺少 <content> 子元素(错误写法)

即使注释详情为空,也必须同时写出 <title> 和 <content>。

<sklandDocument>
    <itemId>84</itemId>
    <metainfo>
        <name>缺少详情元素</name>
        <cover/>
        <subTypes/>
    </metainfo>
    <description><annotation><title>仅有标题</title></annotation></description>
</sklandDocument>

转换器抛出 XmlWikiConversionError: <annotation> must contain exactly one <title> and one <content>.。补上空的 <content/> 即可修复。

技术摘要

项目<annotation><title><content>
内容类别行内注释元素注释标题容器注释详情块容器
允许的内容恰好 1 个 <title> 与 1 个 <content>(顺序不限)除 <annotation> 外的行内元素与文本除 <annotation> 外的混合块级内容(位于 <td>/<th> 内时同时禁止 <table>)
允许的父元素支持行内富文本的容器(非纯文本容器)<annotation><annotation>
是否可为空否(必须含 <title> 与 <content>)是是
对应 JSON 结构{ kind: "annotation", annotation: { inlineElements, childIds } }annotation.inlineElementsannotation.childIds 引用的 blockMap 块

实现说明

  • 子元素顺序宽松:解析时允许 <content> 写在 <title> 之前,但规范化渲染始终按 <title> 在前、<content> 在后输出。
  • 标题空白保留:<title> 使用 preserveWhitespace: true 解析,独立保留内部文字与空白,不受外层段落空白折叠影响;但文字样式必须在 <title> 和 <content> 各自内部表达,外层 <b> 等样式不会穿透到 <annotation> 内部。
  • 继承章节尺寸:当 <annotation> 位于 <chapter> 内且 <content> 中包含省略 widths 的复杂表格时,转换器会沿 DOM 祖先链读取所在 <chapter> 的 size 以推导默认列宽。
  • 历史 parentId 兼容与 ID 复用:从 Wiki JSON 读取注释时以 childIds 为准,兼容原始样本中详情块 parentId 与所属段落不匹配的历史数据;使用 referenceJson 时支持复用详情块及其内部组件的 ID。

另见