{"_id":"mdast-util-toc@7.2.0","bugs":{"url":"https://github.com/syntax-tree/mdast-util-toc/issues"},"dist":{"shasum":"c1e8790ffdb261666939c1310c0b91ef0ed6f8f0","tarball":"http://registry-npm.ywwl.com/mdast-util-toc/download/mdast-util-toc-7.2.0.tgz","fileCount":18,"integrity":"sha512-9fyyMkuEh28CW7EtUTDzf0TgTXyfyKpD1tC17wWaBqsTWJ3JADfkwluUyhORpQoZGJBcoMvk3Wz4IHh9PSbYWA==","signatures":[{"sig":"MEUCIHqjPrIimWkK59L0/5PVu2fvzXNKTKwQZIBwkETLqRwNAiEAr67Q7iCshj9bOZZVOxRemiNsP+NLRfndIKe6xKzQ9c4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD61XOAtUPXKhv5WXwlZk6TkG2NQ8BPp3YGYMukAaQQDQIgPK7RMYLHVbfTaC24sRDdkF8LDHRCaTghiBeq1b1B0+k="}],"unpackedSize":35274,"size":10292,"noattachment":false,"key":"/mdast-util-toc/-/mdast-util-toc-7.2.0.tgz"},"name":"mdast-util-toc","type":"module","types":"./index.d.ts","author":{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},"exports":"./index.js","funding":{"url":"https://opencollective.com/unified","type":"opencollective"},"gitHead":"e0265f19d49df1dd1a628f984ab7767b0eccedfc","license":"MIT","scripts":{"test":"npm run build && npm run format && npm run test-coverage","build":"tsc --build --clean && tsc --build && type-coverage","format":"remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix","prepack":"npm run build && npm run format","test-api":"node --conditions development test/index.js","test-coverage":"c8 --100 --reporter lcov -- npm run test-api"},"version":"7.2.0","_npmUser":{"name":"wooorm","email":"tituswormer@gmail.com"},"homepage":"https://github.com/syntax-tree/mdast-util-toc#readme","keywords":["contents","markdown","mdast-util","mdast","table","toc","unist","utility","util"],"prettier":{"semi":false,"useTabs":false,"tabWidth":2,"singleQuote":true,"trailingComma":"none","bracketSpacing":false},"repository":{"url":"git+https://github.com/syntax-tree/mdast-util-toc.git","type":"git"},"_npmVersion":"12.2.2","description":"mdast utility to generate a table of contents from a tree","directories":{},"maintainers":[{"name":"wooorm","email":"tituswormer@gmail.com"},{"name":"kmck","email":"keith@mcknig.ht"}],"sideEffects":false,"_nodeVersion":"26.12.1","contributors":[{"url":"https://wooorm.com","name":"Titus Wormer","email":"tituswormer@gmail.com"},{"url":"https://barrythepenguin.github.io","name":"Jonathan Haines","email":"jonno.haines@gmail.com"}],"dependencies":{"@types/mdast":"^4.0.0","unist-util-is":"^6.0.0","github-slugger":"^2.0.0","unist-util-visit":"^5.0.0","mdast-util-to-string":"^4.0.0","@ungap/structured-clone":"^1.0.0","@types/ungap__structured-clone":"^1.0.0"},"remarkConfig":{"plugins":["remark-preset-wooorm"]},"typeCoverage":{"strict":true,"atLeast":100},"_hasShrinkwrap":false,"devDependencies":{"c8":"^12.0.0","xo":"^5.0.0","prettier":"^3.0.0","remark-cli":"^12.0.0","typescript":"^6.0.0","@types/node":"^26.0.0","type-coverage":"^2.0.0","mdast-util-gfm":"^3.0.0","remark-preset-wooorm":"^11.0.0","micromark-extension-gfm":"^3.0.0","mdast-util-from-markdown":"^2.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mdast-util-toc_7.2.0_1794571540238_0.3553340675552934"},"readme":"# mdast-util-toc\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n[![Size][badge-size-image]][badge-size-url]\n\n[mdast][github-mdast] utility to generate a table of contents.\n\n## Contents\n\n* [What is this?](#what-is-this)\n* [When should I use this?](#when-should-i-use-this)\n* [Install](#install)\n* [Use](#use)\n* [API](#api)\n  * [`toc(tree[, options])`](#toctree-options)\n  * [`Options`](#options)\n  * [`Result`](#result)\n* [HTML](#html)\n* [Types](#types)\n* [Compatibility](#compatibility)\n* [Security](#security)\n* [Related](#related)\n* [Contribute](#contribute)\n* [License](#license)\n\n## What is this?\n\nThis package is a utility that generates a table of contents from a document.\n\n## When should I use this?\n\nThis utility is useful to generate a section so users can more easily navigate\nthrough a document.\n\nThis package is wrapped in [`remark-toc`][github-remark-toc]\nfor ease of use with [remark][github-remark],\nwhere it also injects the table of contents into the document.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+), install with [npm][npmjs-install]:\n\n```sh\nnpm install mdast-util-toc\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n<script type=\"module\">\n  import {toc} from 'https://esm.sh/mdast-util-toc@7?bundle'\n</script>\n```\n\n## Use\n\n```js\n/**\n * @import {Root} from 'mdast'\n */\n\nimport {toc} from 'mdast-util-toc'\n\n/** @type {Root} */\nconst tree = {\n  type: 'root',\n  children: [\n    {type: 'heading', depth: 1, children: [{type: 'text', value: 'Alpha'}]},\n    {type: 'heading', depth: 2, children: [{type: 'text', value: 'Bravo'}]},\n    {type: 'heading', depth: 3, children: [{type: 'text', value: 'Charlie'}]},\n    {type: 'heading', depth: 2, children: [{type: 'text', value: 'Delta'}]}\n  ]\n}\n\nconst table = toc(tree)\n\nconsole.dir(table, {depth: 3})\n```\n\nYields:\n\n```javascript\n{\n  index: undefined,\n  endIndex: undefined,\n  map: {\n    type: 'list',\n    ordered: false,\n    spread: true,\n    children: [ { type: 'listItem', spread: true, children: [Array] } ]\n  }\n}\n```\n\n## API\n\nThis package exports the identifier [`toc`][api-toc].\nThere is no default export.\n\n### `toc(tree[, options])`\n\nGenerate a table of contents from `tree`.\n\nLooks for the first heading matching `options.heading` (case insensitive) and\nreturns a table of contents (a list) for all following headings.\nIf no `heading` is specified, creates a table of contents for all headings in\n`tree`.\n`tree` is not changed.\n\nLinks in the list to headings are based on GitHub’s style.\nOnly top-level headings (those not in blockquotes or lists) are used.\nThis default behavior can be changed by passing `options.parents`.\n\n###### Parameters\n\n* `tree` ([`Node`][github-mdast-node])\n  — tree to search and generate from\n* `options` ([`Options`][api-options], optional)\n  — configuration\n\n###### Returns\n\nResults ([`Result`][api-result]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n* `heading` (`string`, optional)\n  — heading to look for, wrapped in `new RegExp('^(' + value + ')$', 'i')`\n* `maxDepth` (`number`, default: `6`)\n  — maximum heading depth to include in the table of contents.\n  This is inclusive: when set to `3`, level three headings are included\n  (those with three hashes, `###`)\n* `minDepth` (`number`, default: `1`)\n  — minimum heading depth to include in the table of contents.\n  This is inclusive: when set to `3`, level three headings are included\n  (those with three hashes, `###`)\n* `skip` (`string`, optional)\n  — headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`.\n  Any heading matching this expression will not be present in the table of\n  contents\n* `parents` ([`Test`][github-unist-util-is-test], default: `tree`)\n  — allow headings to be children of certain node types.\n  Can be any [`unist-util-is`][github-unist-util-is] compatible test\n* `tagfilter` (`boolean`, default: `false`)\n  — whether to handle HTML tags according to\n  [GFM tagfilter][github-gfm-tagfilter]\n* `tight` (`boolean`, default: `false`)\n  — whether to compile list items tightly\n* `ordered` (`boolean`, default: `false`)\n  — whether to compile list items as an ordered list, otherwise they are\n  unordered\n* `prefix` (`string`, optional)\n  — add a prefix to links to headings in the table of contents.\n  Useful for example when later going from mdast to hast and sanitizing with\n  `hast-util-sanitize`.\n\n### `Result`\n\nResults (TypeScript type).\n\n###### Fields\n\n* `index` (`number` or `undefined`)\n  — index of the node right after the table of contents heading, `-1` if no\n  heading was found, `undefined` if no `heading` was given\n* `endIndex` (`number` or `undefined`)\n  — index of the first node after `heading` that is not part of its section,\n  `-1` if no heading was found, `undefined` if no `heading` was given, same as\n  `index` if there are no nodes between `heading` and the first heading in\n  the table of contents\n* `map` ([`List`][github-mdast-list] or `undefined`)\n  — list representing the generated table of contents, `undefined` if no\n  table of contents could be created, either because no heading was found or\n  because no following headings were found\n\n## HTML\n\nThis utility does not add IDs to headings.\nLinks in the table of contents point to the IDs that GitHub or\n[`rehype-slug`][github-rehype-slug] would use.\n\nHTML in headings is turned into slugs like GitHub,\nespecially if `tagfilter` is on.\nGFM footnotes are correctly numbered if\n[`mdast-util-gfm-footnote`][github-mdast-util-gfm-footnote] is used.\nThe exception is HTML that changes the document structure,\nsuch as a `</h2>` in a heading as that would require a complete HTML parser.\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the types [`Options`][api-options] and [`Result`][api-result].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `mdast-util-toc@^7`,\ncompatible with Node.js 16.\n\n## Security\n\nUse of `mdast-util-toc` does not change the tree\nand does not involve [hast][github-hast],\nso on its own it does not open you up to\n[cross-site scripting (XSS)][wikipedia-xss]\nattacks.\n\nBut the content of headings is copied into the table of contents,\nso dangerous content in headings\n(such as embedded HTML)\nalso ends up in `map`.\nThe following example shows how an existing script is copied into the table of\ncontents.\n\nFor the following Markdown:\n\n```markdown\n# Alpha\n\n## Bravo<script>alert(1)</script>\n\n## Charlie\n```\n\nYields `map`, serialized:\n\n```markdown\n* [Alpha](#alpha)\n\n  * [Bravo<script>alert(1)</script>](#bravoscriptalert1script)\n  * [Charlie](#charlie)\n```\n\nAlways use [`hast-util-sanitize`][github-hast-util-sanitize]\nwhen transforming to [hast][github-hast].\n\n## Related\n\n* [`github-slugger`](https://github.com/Flet/github-slugger)\n  — generate a slug just like GitHub does\n* [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit)\n  — visit nodes\n* [`unist-util-visit-parents`](https://github.com/syntax-tree/unist-util-visit-parents)\n  — like `visit`, but with a stack of parents\n\n## Contribute\n\nSee\n[`contributing.md`][health-contributing]\nin\n[`syntax-tree/.github`][health]\nfor ways to get started.\nSee [`support.md`][health-support] for ways to get help.\n\nThis project has a [code of conduct][health-coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][file-license] © [Jonathan Haines][barrythepenguin]\n\n<!-- Definitions -->\n\n[api-options]: #options\n\n[api-result]: #result\n\n[api-toc]: #toctree-options\n\n[badge-build-image]: https://github.com/syntax-tree/mdast-util-toc/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/syntax-tree/mdast-util-toc/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-toc.svg\n\n[badge-coverage-url]: https://codecov.io/github/syntax-tree/mdast-util-toc\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/mdast-util-toc.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/mdast-util-toc\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/mdast-util-toc\n\n[badge-size-url]: https://bundlejs.com/?q=mdast-util-toc\n\n[barrythepenguin]: https://barrythepenguin.github.io\n\n[esmsh]: https://esm.sh\n\n[file-license]: license\n\n[github-gfm-tagfilter]: https://github.github.com/gfm/#disallowed-raw-html-extension-\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-hast]: https://github.com/syntax-tree/hast\n\n[github-hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize\n\n[github-mdast]: https://github.com/syntax-tree/mdast\n\n[github-mdast-list]: https://github.com/syntax-tree/mdast#list\n\n[github-mdast-node]: https://github.com/syntax-tree/mdast#node\n\n[github-mdast-util-gfm-footnote]: https://github.com/syntax-tree/mdast-util-gfm-footnote\n\n[github-rehype-slug]: https://github.com/rehypejs/rehype-slug\n\n[github-remark]: https://github.com/remarkjs/remark\n\n[github-remark-toc]: https://github.com/remarkjs/remark-toc\n\n[github-unist-util-is]: https://github.com/syntax-tree/unist-util-is\n\n[github-unist-util-is-test]: https://github.com/syntax-tree/unist-util-is#test\n\n[health]: https://github.com/syntax-tree/.github\n\n[health-coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md\n\n[health-contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md\n\n[health-support]: https://github.com/syntax-tree/.github/blob/main/support.md\n\n[npmjs-install]: https://docs.npmjs.com/cli/install\n\n[typescript]: https://www.typescriptlang.org\n\n[wikipedia-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n","publish_time":1794571540341,"_cnpm_publish_time":1794571540341,"dist-tags":{"latest":"7.2.0"}}