目錄
目錄會在文件本文插入標題項目,與導覽用的大綱面板是不同功能。在 Docs 核心設定中,建立文件前加入以下外掛,將 UI 語言包合併至 locales 並載入樣式。Docs 核心與進階預設都未包含這兩個外掛。
Shell
pnpm add @univerjs/docs-toc @univerjs/docs-toc-uiShell
npm install @univerjs/docs-toc @univerjs/docs-toc-uiShell
yarn add @univerjs/docs-toc @univerjs/docs-toc-uiShell
bun add @univerjs/docs-toc @univerjs/docs-toc-uiTypeScript
import { UniverDocsTocPlugin } from '@univerjs/docs-toc'import { UniverDocsTocUIPlugin } from '@univerjs/docs-toc-ui'import FeatureLocale from '@univerjs/docs-toc-ui/locale/zh-TW'import { LocaleType } from '@univerjs/core'import '@univerjs/docs-toc-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_TW, FeatureLocale)univer.registerPlugin(UniverDocsTocPlugin)univer.registerPlugin(UniverDocsTocUIPlugin)插入與更新
插入前先將游標放入文件。UI 支援插入、更新整份目錄、僅更新頁碼與刪除。未傳入 rangeId 時,更新目前選取範圍所在的目錄。
TypeScript
import { InsertTableOfContentsCommand, UpdateTableOfContentsCommand } from '@univerjs/docs-toc'await univerAPI.executeCommand(InsertTableOfContentsCommand.id, { levels: 3, showPageNumbers: true, rightAlignPageNumbers: true,})await univerAPI.executeCommand(UpdateTableOfContentsCommand.id, { mode: 'entireTable' })更新器計算大綱層級目錄指令(\o)。其他匯入的 Word 開關會保留於 FIELD 中,但並非全部參與計算。完整參數見命令參考。
你覺得這篇文檔如何?