Table of contents
The table of contents feature lets you insert a widget with a list of headings (section titles) that reflects the structure of the document. The list stays up–to–date automatically as the user works on the document. Clicking a list item navigates the user to the corresponding document section.
Unlock this feature with a CKEditor Paid Plan. Sign up for a free trial, or select the Plan that provides access to all the premium features you need.
# Demo
Create several headings in the editor and click the table of contents button in the toolbar. Change the heading text or level to see the table of contents getting updated live.
The plant kingdom
The plant kingdom is a diverse group of organisms that includes both tiny algae and giant sequoias. Despite this diversity, all plants have a few things in common.
Plants are organisms that:
- Have bodies made of multiple cells.
- Can synthesize food in a process called photosynthesis.
- Usually can’t move.
- Have cells with walls made of cellulose.
Plants can be divided into two groups: those that make seeds and those that don’t.
Seedless plants
Plants in this group, called cryptogams, do not produce seeds.
Freshwater and marine algae
Green algae do not form true roots, stems, or leaves. This group gave rise to all land plants hundreds of millions of years ago.
Mosses and liverworts
Mosses and liverworts are the oldest land plants. They have a stem and structures resembling leaves and roots. Unlike other land plants, they lack a vascular system (a special tissue to transport water and nutrients).
Ferns and horsetails
Ferns and horsetails have distinct stems, leaves, and roots. They are the oldest vascular plants. This means that, unlike mosses and liverworts, they do have a vascular system that transports water and nutrients through their bodies.
Seed-producing plants
Plants in this group, called phanerogams, can produce seeds.
Non-flowering plants
Members of this group, called gymnosperms, are the first vascular plants to produce seeds. The seeds, unlike in flowering plants, don’t have an outer covering.
Conifers
Most members of this group are evergreen trees and shrubs. They are known for their needles (specialized leaves) and cones (where the seeds are kept).
Ginkgos and cycads
Ginkgos and cycads are both very old plant groups. The only surviving ginkgo species is the ginkgo tree (Ginkgo biloba). Cycads resemble palm trees, but the two are not related. The latter belong to flowering plants.
Flowering plants
When you hear the word ‘plant’, you likely picture a member of this group. Called angiosperms, they form the most diverse and abundant division of the plant kingdom. Plants in this group can make flowers and fruits that enclose seeds.
# Installation
⚠️ New import paths
Starting with version 42.0.0, we changed the format of import paths. This guide uses the new, shorter format. Refer to the Packages in the legacy setup guide if you use an older version of CKEditor 5.
After installing the editor, add the feature to your plugin list and toolbar configuration:
import { ClassicEditor } from 'ckeditor5';
import { TableOfContents } from 'ckeditor5-premium-features';
ClassicEditor
.create( document.querySelector( '#editor' ), {
licenseKey: '<YOUR_LICENSE_KEY>',
plugins: [ TableOfContents, /* ... */ ],
toolbar: [ 'tableOfContents', /* ... */ ]
// ...
} )
.then( /* ... */ )
.catch( /* ... */ );
By default, the table of contents feature takes care of managing the heading IDs and creating proper links with a dedicated href
attribute. The output data produced by this feature ensures that clicking a link in a table of contents will scroll to the corresponding heading in the content.
# Activating the feature
To use this premium feature, you need to activate it with proper credentials. Refer to the License key and activation guide for details.
# Related features
Here are some more CKEditor 5 features that can help you navigate the content of the editor:
- Document outline – Display the list of sections (headings) of the document next to the editor.
- Content minimap – Navigate the document using a miniature overview map placed next to the editor.
- Pagination – See the live preview of the document’s page breaks and quickly navigate between pages.
# Common API
The TableOfContents
plugin registers:
- The
'tableOfContents'
UI button component. - The
'insertTableOfContents'
command implemented byTableOfContentsCommand
.
You can execute the command using the editor.execute()
method:
// Insert the table of contents.
editor.execute( 'insertTableOfContents' );
We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.