{"id":13403622,"url":"https://github.com/jonschlinkert/markdown-toc","last_synced_at":"2025-05-13T21:12:35.877Z","repository":{"id":11721268,"uuid":"14242519","full_name":"jonschlinkert/markdown-toc","owner":"jonschlinkert","description":"API and CLI for generating a markdown TOC (table of contents) for a README or any markdown files. Uses Remarkable to parse markdown. Used by NASA/openmct, Prisma, Joi, Mocha, Sass, Prettier, Orbit DB, FormatJS, Raneto, hapijs/code, webpack-flow, docusaurus, release-it, ts-loader, json-server, reactfire, bunyan, husky, react-easy-state, react-snap, chakra-ui, carbon, alfresco, repolinter, Assemble, Verb, and thousands of other projects.","archived":false,"fork":false,"pushed_at":"2024-08-09T14:53:13.000Z","size":280,"stargazers_count":1689,"open_issues_count":90,"forks_count":713,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-05-06T16:48:10.165Z","etag":null,"topics":["javascript","jonschlinkert","markdown","markdown-toc","md","navigation","node","nodejs","project","readme","remarkable","table-of-contents","toc","toc-generator"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jonschlinkert"}},"created_at":"2013-11-08T19:37:06.000Z","updated_at":"2025-04-27T20:01:29.000Z","dependencies_parsed_at":"2024-11-25T18:05:02.587Z","dependency_job_id":"472b23d0-8622-4675-895e-1c2c6130cf92","html_url":"https://github.com/jonschlinkert/markdown-toc","commit_stats":{"total_commits":217,"total_committers":28,"mean_commits":7.75,"dds":"0.35944700460829493","last_synced_commit":"386b44747f271bfd56956d3ee7714e190dc7037f"},"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmarkdown-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmarkdown-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmarkdown-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fmarkdown-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/markdown-toc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253336316,"owners_count":21892785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jonschlinkert","markdown","markdown-toc","md","navigation","node","nodejs","project","readme","remarkable","table-of-contents","toc","toc-generator"],"created_at":"2024-07-30T19:01:32.479Z","updated_at":"2025-05-13T21:12:30.867Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# markdown-toc [![NPM version](https://img.shields.io/npm/v/markdown-toc.svg?style=flat)](https://www.npmjs.com/package/markdown-toc) [![NPM monthly downloads](https://img.shields.io/npm/dm/markdown-toc.svg?style=flat)](https://npmjs.org/package/markdown-toc) [![NPM total downloads](https://img.shields.io/npm/dt/markdown-toc.svg?style=flat)](https://npmjs.org/package/markdown-toc)\n\n\u003e Generate a markdown TOC (table of contents) with Remarkable.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n- [Highlights](#highlights)\n- [Usage](#usage)\n- [API](#api)\n  * [toc.plugin](#tocplugin)\n  * [toc.json](#tocjson)\n  * [toc.insert](#tocinsert)\n  * [Utility functions](#utility-functions)\n- [Options](#options)\n  * [options.append](#optionsappend)\n  * [options.filter](#optionsfilter)\n  * [options.slugify](#optionsslugify)\n  * [options.bullets](#optionsbullets)\n  * [options.maxdepth](#optionsmaxdepth)\n  * [options.firsth1](#optionsfirsth1)\n  * [options.stripHeadingTags](#optionsstripheadingtags)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save markdown-toc\n```\n\n# Sponsors\n\nThanks to the following companies, organizations, and individuals for supporting the ongoing maintenance and development of markdown-toc! [Become a Sponsor](https://github.com/sponsors/jonschlinkert) to add your logo to this README, or any of [my other projects](https://github.com/jonschlinkert?tab=repositories\u0026q=\u0026type=\u0026language=\u0026sort=stargazers)\n\n## Gold Sponsors\n\n| [\u003cimg src=\"https://github.com/jonschlinkert/clone-deep/assets/383994/98036489-2cae-48a2-8d29-7dec58ea05c4\" alt=\"https://jaake.tech/\" width=\"100\"/\u003e](https://jaake.tech/) |\n|:---:|\n| [https://jaake.tech/](https://jaake.tech/) |\n\n\u003cbr /\u003e\n\n## Quick Start\n\nAssuming you want to add a TOC to README.md:\n\n1. `$ npm install -g markdown-toc`\n2. Edit README.md and insert the following line where you want the TOC inserted:\u003cbr /\u003e`\u003c!-- toc --\u003e`\n3. `$ markdown-toc -i README.md`\n\n## CLI\n\n```\nUsage: markdown-toc [options] \u003cinput\u003e\n\n  input:        The Markdown file to parse for table of contents,\n                or \"-\" to read from stdin.\n\n  -i:           Edit the \u003cinput\u003e file directly, injecting the TOC at - [Highlights](#highlights)\n- [Usage](#usage)\n- [API](#api)\n  * [toc.plugin](#tocplugin)\n  * [toc.json](#tocjson)\n  * [toc.insert](#tocinsert)\n  * [Utility functions](#utility-functions)\n- [Options](#options)\n  * [options.append](#optionsappend)\n  * [options.filter](#optionsfilter)\n  * [options.slugify](#optionsslugify)\n  * [options.bullets](#optionsbullets)\n  * [options.maxdepth](#optionsmaxdepth)\n  * [options.firsth1](#optionsfirsth1)\n  * [options.stripHeadingTags](#optionsstripheadingtags)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_;\n                (Without this flag, the default is to print the TOC to stdout.)\n\n  --json:       Print the TOC in JSON format\n\n  --append:     Append a string to the end of the TOC\n\n  --bullets:    Bullets to use for items in the generated TOC\n                (Supports multiple bullets: --bullets \"*\" --bullets \"-\" --bullets \"+\")\n                (Default is \"*\".)\n\n  --maxdepth:   Use headings whose depth is at most maxdepth\n                (Default is 6.)\n\n  --no-firsth1: Include the first h1-level heading in a file\n\n  --no-stripHeadingTags: Do not strip extraneous HTML tags from heading\n                         text before slugifying\n\n  --indent:     Provide the indentation to use - defaults to '  '\n                (to specify a tab, use the bash-escaped $'\\t')\n```\n\n## Highlights\n\n**Features**\n\n* Can optionally be used as a [remarkable](https://github.com/jonschlinkert/remarkable) plugin\n* Returns an object with the rendered TOC (on `content`), as well as a `json` property with the raw TOC object, so you can generate your own TOC using templates or however you want\n* Works with [repeated headings](https://gist.github.com/jonschlinkert/ac5d8122bfaaa394f896)\n* Uses sane defaults, so no customization is necessary, but you can if you need to.\n* [filter](#filter-headings) out headings you don't want\n* [Improve](#titleize) the headings you do want\n* Use a custom [slugify](#optionsslugify) function to change how links are created\n\n**Safe!**\n\n* Won't mangle markdown in code examples in gfm code blocks that other TOC generators mistake as being actual headings (this happens when markdown headings are show in _examples_, meaning they arent' actually headings that should be in the toc. Also happens with yaml and coffee-script comments, or any comments that use `#`)\n* Won't mangle front-matter, or mistake front-matter properties for headings like other TOC generators\n\n## Usage\n\n```js\nvar toc = require('markdown-toc');\n\ntoc('# One\\n\\n# Two').content;\n// Results in:\n// - [One](#one)\n// - [Two](#two)\n```\n\nTo allow customization of the output, an object is returned with the following properties:\n\n* `content` **{String}**: The generated table of contents. Unless you want to customize rendering, this is all you need.\n* `highest` **{Number}**: The highest level heading found. This is used to adjust indentation.\n* `tokens` **{Array}**: Headings tokens that can be used for custom rendering\n\n## API\n\n### toc.plugin\n\nUse as a [remarkable](https://github.com/jonschlinkert/remarkable) plugin.\n\n```js\nvar Remarkable = require('remarkable');\nvar toc = require('markdown-toc');\n\nfunction render(str, options) {\n  return new Remarkable()\n    .use(toc.plugin(options)) // \u003c= register the plugin\n    .render(str);\n}\n```\n\n**Usage example**\n\n```js\nvar results = render('# AAA\\n# BBB\\n# CCC\\nfoo\\nbar\\nbaz');\n```\n\nResults in:\n\n```\n- [AAA](#aaa)\n- [BBB](#bbb)\n- [CCC](#ccc)\n```\n\n### toc.json\n\nObject for creating a custom TOC.\n\n```js\ntoc('# AAA\\n## BBB\\n### CCC\\nfoo').json;\n\n// results in\n[ { content: 'AAA', slug: 'aaa', lvl: 1 },\n  { content: 'BBB', slug: 'bbb', lvl: 2 },\n  { content: 'CCC', slug: 'ccc', lvl: 3 } ]\n```\n\n### toc.insert\n\nInsert a table of contents immediately after an _opening_ `\u003c!-- toc --\u003e` code comment, or replace an existing TOC if both an _opening_ comment and a _closing_ comment (`\u003c!-- tocstop --\u003e`) are found.\n\n_(This strategy works well since code comments in markdown are hidden when viewed as HTML, like when viewing a README on GitHub README for example)._\n\n**Example**\n\n```\n\u003c!-- toc --\u003e\n- old toc 1\n- old toc 2\n- old toc 3\n\u003c!-- tocstop --\u003e\n\n## abc\nThis is a b c.\n\n## xyz\nThis is x y z.\n```\n\nWould result in something like:\n\n```\n\u003c!-- toc --\u003e\n- [abc](#abc)\n- [xyz](#xyz)\n\u003c!-- tocstop --\u003e\n\n## abc\nThis is a b c.\n\n## xyz\nThis is x y z.\n```\n\n### Utility functions\n\nAs a convenience to folks who wants to create a custom TOC, markdown-toc's internal utility methods are exposed:\n\n```js\nvar toc = require('markdown-toc');\n```\n\n* `toc.bullets()`: render a bullet list from an array of tokens\n* `toc.linkify()`: linking a heading `content` string\n* `toc.slugify()`: slugify a heading `content` string\n* `toc.strip()`: strip words or characters from a heading `content` string\n\n**Example**\n\n```js\nvar result = toc('# AAA\\n## BBB\\n### CCC\\nfoo');\nvar str = '';\n\nresult.json.forEach(function(heading) {\n  str += toc.linkify(heading.content);\n});\n```\n\n## Options\n\n### options.append\n\nAppend a string to the end of the TOC.\n\n```js\ntoc(str, {append: '\\n_(TOC generated by Verb)_'});\n```\n\n### options.filter\n\nType: `Function`\n\nDefault: `undefined`\n\nParams:\n\n* `str` **{String}** the actual heading string\n* `ele` **{Objecct}** object of heading tokens\n* `arr` **{Array}** all of the headings objects\n\n**Example**\n\nFrom time to time, we might get junk like this in our TOC.\n\n```\n[.aaa([foo], ...) another bad heading](#-aaa--foo--------another-bad-heading)\n```\n\nUnless you like that kind of thing, you might want to filter these bad headings out.\n\n```js\nfunction removeJunk(str, ele, arr) {\n  return str.indexOf('...') === -1;\n}\n\nvar result = toc(str, {filter: removeJunk});\n//=\u003e beautiful TOC\n```\n\n### options.slugify\n\nType: `Function`\n\nDefault: Basic non-word character replacement.\n\n**Example**\n\n```js\nvar str = toc('# Some Article', {slugify: require('uslug')});\n```\n\n### options.bullets\n\nType: `String|Array`\n\nDefault: `*`\n\nThe bullet to use for each item in the generated TOC. If passed as an array (`['*', '-', '+']`), the bullet point strings will be used based on the header depth.\n\n### options.maxdepth\n\nType: `Number`\n\nDefault: `6`\n\nUse headings whose depth is at most maxdepth.\n\n### options.firsth1\n\nType: `Boolean`\n\nDefault: `true`\n\nExclude the first h1-level heading in a file. For example, this prevents the first heading in a README from showing up in the TOC.\n\n### options.stripHeadingTags\n\nType: `Boolean`\n\nDefault: `true`\n\nStrip extraneous HTML tags from heading text before slugifying. This is similar to GitHub markdown behavior.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [gfm-code-blocks](https://www.npmjs.com/package/gfm-code-blocks): Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string. | [homepage](https://github.com/jonschlinkert/gfm-code-blocks \"Extract gfm (GitHub Flavored Markdown) fenced code blocks from a string.\")\n* [markdown-link](https://www.npmjs.com/package/markdown-link): Micro util for generating a single markdown link. | [homepage](https://github.com/jonschlinkert/markdown-link \"Micro util for generating a single markdown link.\")\n* [markdown-utils](https://www.npmjs.com/package/markdown-utils): Tiny helpers for creating consistenly-formatted markdown snippets. | [homepage](https://github.com/jonschlinkert/markdown-utils \"Tiny helpers for creating consistenly-formatted markdown snippets.\")\n* [pretty-remarkable](https://www.npmjs.com/package/pretty-remarkable): Plugin for prettifying markdown with Remarkable using custom renderer rules. | [homepage](https://github.com/jonschlinkert/pretty-remarkable \"Plugin for prettifying markdown with Remarkable using custom renderer rules.\")\n* [remarkable](https://www.npmjs.com/package/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in… [more](https://github.com/jonschlinkert/remarkable) | [homepage](https://github.com/jonschlinkert/remarkable \"Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in one.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |\n| --- | --- |\n| 199 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 9   | [doowb](https://github.com/doowb) |\n| 4   | [dbooth-boston](https://github.com/dbooth-boston) |\n| 3   | [sapegin](https://github.com/sapegin) |\n| 3   | [Marsup](https://github.com/Marsup) |\n| 2   | [dvcrn](https://github.com/dvcrn) |\n| 2   | [maxogden](https://github.com/maxogden) |\n| 2   | [twang2218](https://github.com/twang2218) |\n| 2   | [zeke](https://github.com/zeke) |\n| 1   | [Vortex375](https://github.com/Vortex375) |\n| 1   | [chendaniely](https://github.com/chendaniely) |\n| 1   | [Daniel-Mietchen](https://github.com/Daniel-Mietchen) |\n| 1   | [Feder1co5oave](https://github.com/Feder1co5oave) |\n| 1   | [garygreen](https://github.com/garygreen) |\n| 1   | [TehShrike](https://github.com/TehShrike) |\n| 1   | [citizenmatt](https://github.com/citizenmatt) |\n| 1   | [mgroenhoff](https://github.com/mgroenhoff) |\n| 1   | [rafaelsteil](https://github.com/rafaelsteil) |\n| 1   | [RichardBradley](https://github.com/RichardBradley) |\n| 1   | [sethvincent](https://github.com/sethvincent) |\n| 1   | [shanehughes3](https://github.com/shanehughes3) |\n| 1   | [bcho](https://github.com/bcho) |\n| 1   | [lu22do](https://github.com/lu22do) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2023, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 12, 2023._","funding_links":["https://github.com/sponsors/jonschlinkert"],"categories":["JavaScript","Uncategorized","README Generators","Markdown Building Blocks","Table of Contents"],"sub_categories":["Uncategorized","Dynamic Badges","Markdown to Table of Contents (TOC)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fmarkdown-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fmarkdown-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fmarkdown-toc/lists"}