脚注与尾注
在传统分页文档中插入脚注与尾注。脚注排版在引用所在页面,尾注按文档的尾注设置放置。此 API 不支持现代文档。
安装
将以下插件加入已配置许可证的 Docs 编辑器,并加载 UI 样式和与编辑器一致的语言资源。
UniverDocsAdvancedPreset 已包含这两个插件。使用该 preset 时,无需再次注册。
Shell
pnpm add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-uiShell
npm install @univerjs-pro/docs-reference @univerjs-pro/docs-reference-uiShell
yarn add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-uiShell
bun add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-uiTypeScript
import { UniverDocsReferencePlugin } from '@univerjs-pro/docs-reference'import { UniverDocsReferenceUIPlugin } from '@univerjs-pro/docs-reference-ui'import ReferenceLocale from '@univerjs-pro/docs-reference-ui/locale/zh-CN'import { LocaleType } from '@univerjs/core'import '@univerjs-pro/docs-reference/facade'import '@univerjs-pro/docs-reference-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_CN, ReferenceLocale)univer.registerPlugin(UniverDocsReferencePlugin)univer.registerPlugin(UniverDocsReferenceUIPlugin)插入与管理注释
TypeScript
const document = univerAPI.getActiveDocument()if (document) { const noteId = document.insertFootnote(0) if (noteId) console.log(document.getParagraphs(noteId)) console.log(document.getFootnotes(), document.getEndnotes())}偏移量是正文中的 UTF-16 位置,包含结构标记。位置或内容无效、缺少编辑权限,或当前为现代文档时,插入返回 null;成功时返回稳定的注释 ID。引用与注释内容参与同一次撤销和协同 mutation。
使用 getFootnotes() / getEndnotes() 读取注释,使用 deleteFootnote(noteId) / deleteEndnote(noteId) 删除。setFootnoteSettings() 和 setEndnoteSettings() 配置编号与位置,传入 null 可重置显式设置。定位内容时保存并使用返回的注释 ID;显示编号可能在重新分页后变化。
你觉得这篇文档如何?