
Security News
Security Community Slams MIT-linked Report Claiming AI Powers 80% of Ransomware
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.
remark-toc
Advanced tools
remark plugin to generate a table of contents.
npm:
npm install remark-toc
Say we have the following file, example.md:
# Alpha
## Table of Contents
## Bravo
### Charlie
## Delta
And our script, example.js, looks as follows:
var vfile = require('to-vfile')
var remark = require('remark')
var toc = require('remark-toc')
remark()
  .use(toc)
  .process(vfile.readSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })
Now, running node example yields:
# Alpha
## Table of Contents
-   [Bravo](#bravo)
    -   [Charlie](#charlie)
-   [Delta](#delta)
## Bravo
### Charlie
## Delta
remark().use(toc[, options])Generate a table of contents.
'Table of Contents', 'toc',
or 'table-of-contents' (case insensitive, supports alt/title attributes
for links and images too)Note: if you’re later compiling to HTML, you still need to add anchors to headings. Previously that was done by this plugin as well, but now you must
.use(slug)to includeremark-slugexplicitly.
optionsAll options are passed to mdast-util-toc, with the exception that
heading defaults to 'toc|table[ -]of[ -]contents?'.
Use of remark-toc involves user content and changes the tree, so it can open
you up for a cross-site scripting (XSS) attack.
Existing nodes are copied into the table of contents. The following example shows how an existing script is copied into the table of contents.
The following Markdown:
# Table of Contents
## Bravo<script>alert(1)</script>
## Charlie
Yields:
# Table of Contents
-   [Bravo<script>alert(1)</script>](#bravoscriptalert1script)
-   [Charlie](#charlie)
## Bravo<script>alert(1)</script>
## Charlie
This may become a problem if the Markdown is later transformed to rehype (hast) or opened in an unsafe Markdown viewer.
remark-slug
– Add anchors to headings using GitHub’s algorithmremark-collapse
– Make a section collapsibleremark-normalize-headings
— Make sure there is no more than a single top-level heading in the document
and rewrite the rest accordinglyremark-behead
— Change header levelsmdast-util-toc
— Core functionality of this pluginSee contributing.md in remarkjs/.github for ways
to get started.
See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
The markdown-toc package generates a table of contents for markdown files. It is a standalone tool that can be used via the command line or as a library in Node.js. Unlike remark-toc, which is a plugin for the remark processor, markdown-toc is a more general-purpose tool that can be used independently of any specific markdown processor.
The doctoc package is a command-line tool that generates a table of contents for markdown files. It is designed to be used as a standalone tool and can automatically update the TOC in place. Compared to remark-toc, doctoc is more focused on being a CLI tool and does not integrate directly with the remark processor.
FAQs
remark plugin to generate a table of contents (TOC)
The npm package remark-toc receives a total of 293,394 weekly downloads. As such, remark-toc popularity was classified as popular.
We found that remark-toc demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.

Research
/Security News
Socket researchers found 10 typosquatted npm packages that auto-run on install, show fake CAPTCHAs, fingerprint by IP, and deploy a credential stealer.