Table of Contents
A table of contents writes entries for headings into the document body and is separate from the outline navigation panel. Add these two plugins to the Docs core setup before creating a document, merge the UI locale into locales, and load the stylesheet. Neither Docs core nor the Docs advanced preset includes them.
The table of contents is available in Traditional documents. In Modern documents, Univer hides the table of contents menu.
pnpm add @univerjs/docs-toc @univerjs/docs-toc-uinpm install @univerjs/docs-toc @univerjs/docs-toc-uiyarn add @univerjs/docs-toc @univerjs/docs-toc-uibun add @univerjs/docs-toc @univerjs/docs-toc-uiimport { UniverDocsTocPlugin } from '@univerjs/docs-toc'import { UniverDocsTocUIPlugin } from '@univerjs/docs-toc-ui'import FeatureLocale from '@univerjs/docs-toc-ui/locale/en-US'import { LocaleType } from '@univerjs/core'import '@univerjs/docs-toc-ui/lib/index.css'univerAPI.loadLocales(LocaleType.EN_US, FeatureLocale)univer.registerPlugin(UniverDocsTocPlugin)univer.registerPlugin(UniverDocsTocUIPlugin)Insert and update
Place the cursor in the document before inserting. The UI handles insertion, full updates, page-number-only updates, and deletion. When rangeId is not passed, an update targets the table of contents at the current selection.
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' })The updater evaluates outline-level table-of-contents instructions (\o). Other Word switches from an imported file remain in the FIELD metadata, but not all of them are evaluated. See the command parameters.
How is this guide?