# 脚注与尾注

- Human documentation: [https://docs.univer.ai/zh-CN/guides/docs/features/footnotes](https://docs.univer.ai/zh-CN/guides/docs/features/footnotes)

- Agent Markdown: [https://docs.univer.ai/zh-CN/guides/docs/features/footnotes.md](https://docs.univer.ai/zh-CN/guides/docs/features/footnotes.md)

- Requested language: `zh-CN`

- Content language: `zh-CN`

- Documentation version: `1.0.0-rc.0`

- Source: [docs/features/footnotes.zh-CN.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/features/footnotes.zh-CN.mdx)

---

#### Package metadata

```json
{
  "preset": [
    {
      "client": "@univerjs/preset-docs-advanced",
      "locale": "@univerjs/preset-docs-advanced/locales/zh-CN",
      "style": "@univerjs/preset-docs-advanced/lib/index.css"
    }
  ],
  "plugins": [
    {
      "client": "@univerjs-pro/docs-reference",
      "facade": "@univerjs-pro/docs-reference/facade"
    },
    {
      "client": "@univerjs-pro/docs-reference-ui",
      "locale": "@univerjs-pro/docs-reference-ui/locale/zh-CN",
      "style": "@univerjs-pro/docs-reference-ui/lib/index.css"
    }
  ],
  "license": true,
  "server": false
}
```

在传统分页文档中插入脚注与尾注。脚注排版在引用所在页面，尾注按文档的尾注设置放置。此 API 不支持现代文档。

## 安装

将以下插件加入已配置许可证的 Docs 编辑器，并加载 UI 样式和与编辑器一致的语言资源。

`UniverDocsAdvancedPreset` 已包含这两个插件。使用该 preset 时，无需再次注册。

#### npm

```bash
npm install @univerjs-pro/docs-reference @univerjs-pro/docs-reference-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-ui
```

#### yarn

```bash
yarn add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-ui
```

#### bun

```bash
bun add @univerjs-pro/docs-reference @univerjs-pro/docs-reference-ui
```

```ts
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)
```

## 插入与管理注释

```ts
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；显示编号可能在重新分页后变化。
