
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
eleventy-plugin-toc
Advanced tools
This Eleventy plugin will generate a TOC from page content using an Eleventy filter.
{
tags: ['h2', 'h3', 'h4'], // which heading tags are selected headings must each have an ID attribute
wrapper: 'nav', // element to put around the root `ol`/`ul`
wrapperClass: 'toc', // class for the element around the root `ol`/`ul`
ul: false, // if to use `ul` instead of `ol`
flat: false, // if subheadings should appear as child of parent or as a sibling
}
npm i --save eleventy-plugin-toc
Your heading elements must have ids before this plugin will create a TOC. If there aren't ids on your headings, there will be no anchors for this plugin to link to.
I use markdown-it-anchor to add those ids to the headings: Eleventy config example
// .eleventy.js
const markdownIt = require('markdown-it')
const markdownItAnchor = require('markdown-it-anchor')
module.exports = eleventyConfig => {
// Markdown
eleventyConfig.setLibrary(
'md',
markdownIt().use(markdownItAnchor)
)
// ... your other Eleventy config options
}
// .eleventy.js
const pluginTOC = require('eleventy-plugin-toc')
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginTOC)
}
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(pluginTOC, {
tags: ['h2', 'h3'],
wrapper: 'div'
})
}
Because Eleventy only provides the content variable to layout templates (not to content files), you'll need to put this markup in a layout template:
<article>
{{ content }}
</article>
<aside>
{{ content | toc }}
</aside>
If you're using Nunjucks, include the safe filter:
<article>
{{ content | safe }}
</article>
<aside>
{{ content | toc | safe }}
</aside>
If you want to conditionally render a wrapper element, the filter will return undefined when no markup is generated:
{% if content | toc %}
<aside>
{{ content | toc }}
</aside>
{% endif %}
Pass a stringified JSON object (must be JSON.parse()-able) as an option for in your template. Because this is an object, you only need to include the key-value pairs you need to override; defaults will be preserved.
<aside>
{{ content | toc: '{"tags":["h2","h3"],"wrapper":"div","wrapperClass":"content-tableau"}' }}
</aside>
FAQs
Eleventy filter to generate a Table of Contents in a template
The npm package eleventy-plugin-toc receives a total of 2,908 weekly downloads. As such, eleventy-plugin-toc popularity was classified as popular.
We found that eleventy-plugin-toc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.