Adds an addbar button for generating a table of contents from document headings. The ToC block updates automatically when headings change.
Open the addbar and choose Insert ToC to build a linked outline from h1–h6 headings. Click a ToC link to scroll to the heading.
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/toc/toc.js"></script>
const app = Redactor('#entry', {
plugins: ['toc']
});
number)
31–6).string | false)
falsestring | false)
falsefalse prepends the ToC to the editor.boolean)
falsetrue, also adds the button to the main toolbar.boolean)
truetrue, only top-level heading blocks are included.string)
Redactor('#entry', {
plugins: ['toc'],
toc: {
depth: 4,
title: 'Contents',
toolbar: true
}
});
en: {
toc: {
'insert-toc': 'Insert ToC'
}
}
This plugin does not emit events.
Builds and inserts (or replaces) the table of contents from current headings.
app.toc.generate();
Refreshes an existing ToC block to match current headings. Called automatically on editor:change.
app.toc.update();