{"id":19607891,"url":"https://github.com/mkdoc/mktoc","last_synced_at":"2025-09-15T23:30:46.091Z","repository":{"id":57142781,"uuid":"54697655","full_name":"mkdoc/mktoc","owner":"mkdoc","description":"Generates a table of contents index","archived":false,"fork":false,"pushed_at":"2017-02-10T05:55:04.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-11T10:12:47.831Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mkdoc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-25T05:51:46.000Z","updated_at":"2016-03-25T05:52:04.000Z","dependencies_parsed_at":"2022-09-05T22:30:11.349Z","dependency_job_id":null,"html_url":"https://github.com/mkdoc/mktoc","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkdoc%2Fmktoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkdoc%2Fmktoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkdoc%2Fmktoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkdoc%2Fmktoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkdoc","download_url":"https://codeload.github.com/mkdoc/mktoc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233165124,"owners_count":18634871,"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":[],"created_at":"2024-11-11T10:12:52.699Z","updated_at":"2025-09-15T23:30:40.812Z","avatar_url":"https://github.com/mkdoc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Contents Index\n\n[![Build Status](https://travis-ci.org/mkdoc/mktoc.svg?v=3)](https://travis-ci.org/mkdoc/mktoc)\n[![npm version](http://img.shields.io/npm/v/mktoc.svg?v=3)](https://npmjs.org/package/mktoc)\n[![Coverage Status](https://coveralls.io/repos/mkdoc/mktoc/badge.svg?branch=master\u0026service=github\u0026v=3)](https://coveralls.io/github/mkdoc/mktoc?branch=master)\n\n\u003e Generate a table of contents index\n\nCreates a list representing the structure of a document as determined by the headings in the document.\n\nTo inject the created list into a location in the document place the marker `\u003c!-- @toc --\u003e` in the source document.\n\nBy default it creates anchor links (`#`) to named anchors on the same page but the link behaviour may be disabled or customized using a `destination` function, see the [api docs](#api).\n\n## Install\n\n```\nnpm i mktoc --save\n```\n\nFor the command line interface install [mkdoc][] globally (`npm i -g mkdoc`).\n\n---\n\n- [Install](#install)\n- [Usage](#usage)\n- [Example](#example)\n- [Help](#help)\n- [API](#api)\n  - [toc](#toc)\n  - [Toc](#toc-1)\n- [License](#license)\n\n---\n\n## Usage\n\nCreate the stream and write a [commonmark][] document:\n\n```javascript\nvar toc = require('mktoc')\n  , ast = require('mkast');\nast.src('# Heading\\n\\n## Sub Heading\\n\\n')\n  .pipe(toc())\n  .pipe(ast.stringify({indent: 2}))\n  .pipe(process.stdout);\n```\n\n## Example\n\nCreate a standalone table of contents:\n\n```shell\nmkcat README.md | mktoc -s | mkout \u003e TOC.md\n```\n\nInject the table of contents into a document containing the `\u003c!-- @toc --\u003e` marker:\n\n```shell\nmkcat readme.md | mktoc | mkout \u003e README.md\n```\n\nSet an initial heading with the specified level:\n\n```shell\nmkcat readme.md | mktoc --title 'Table of Contents' --level 2 | mkout \u003e README.md\n```\n\nOnly include headings for levels 2-4:\n\n```shell\nmkcat readme.md | mktoc -d 2 -m 4 | mkout \u003e README.md\n```\n\nCreate an ordered list and set the delimiter:\n\n```shell\nmkcat readme.md | mktoc -o -E '.' | mkout \u003e README.md\n```\n\n## Help\n\n```\nUsage: mktoc [options]\n\n  Generates a table of contents index.\n\nOptions\n  -t, --title=[TITLE]     Set initial heading\n  -l, --level=[NUM]       Set level for initial heading\n  -d, --depth=[LEVEL]     Ignore headings below LEVEL\n  -m, --max=[LEVEL]       Ignore headings above LEVEL\n  -p, --prefix=[VAL]      Set link destination prefix to VAL\n  -b, --base=[URL]        Base URL for absolute links\n  -B, --bullet=[CHAR]     Character for bullet lists\n  -E, --delimiter=[CHAR]  Delimiter for ordered lists\n  -D, --disable           Disable automatic links\n  -o, --ordered           Create an ordered list\n  -s, --standalone        Standalone index, discards input\n  -h, --help              Display help and exit\n  --version               Print the version and exit\n\nmktoc@1.0.8\n```\n\n## API\n\n### toc\n\n```javascript\ntoc([opts][, cb])\n```\n\nGenerate a document containing a table of contents list.\n\nSee [Toc](#toc-1) for more available options.\n\nReturns an output stream.\n\n* `opts` Object processing options.\n* `cb` Function callback function.\n\n#### Options\n\n* `input` Readable input stream.\n* `output` Writable output stream.\n\n### Toc\n\n```javascript\nnew Toc([opts])\n```\n\nCreate a table of contents index stream.\n\nNote that in order to build a complete index all data must be read so this\nimplementation buffers incoming nodes and flushes them when the stream\nis ended writing the index nodes where necessary.\n\nWhen the first child of a heading is a link it is preserved and no\nautomatic link is created, otherwise when creating links inline markup\nin the heading is discarded.\n\nIf the `standalone` option is given then the incoming data is discarded\nand the document representing the index is flushed.\n\nWhen a `destination` function is specified it is passed a string\nliteral of the heading text and should return a URL, the function is\ninvoked in the scope of this stream.\n\nTypically `prefix` will be either a `/`, `#` or the empty string\ndepending upon whether you want absolute, anchor or relative links. The\ndefault is to use `#` for anchor links on the same page.\n\nIf the `bullet` option is given it must be one of `-`, `+` or `*`.\n\nIf the `delimiter` option is given it must a period `.` or right\nparenthesis `)`.\n\n* `opts` Object processing options.\n\n#### Options\n\n* `standalone` Boolean discard incoming data.\n* `type` String=bullet list output type, `bullet` or `ordered`.\n* `link` Boolean=true whether to create links in the output lists.\n* `depth` Number=1 ignore headings below this level.\n* `max` Number=6 ignore headings above this level.\n* `destination` Function builds the link URLs.\n* `prefix` String=# default link prefix.\n* `base` String a base path for absolute links.\n* `bullet` String=- character for bullet lists.\n* `delimiter` String=) delimiter for ordered lists.\n\n## License\n\nMIT\n\n---\n\nCreated by [mkdoc](https://github.com/mkdoc/mkdoc) on April 18, 2016\n\n[mkdoc]: https://github.com/mkdoc/mkdoc\n[commonmark]: http://commonmark.org\n[jshint]: http://jshint.com\n[jscs]: http://jscs.info\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkdoc%2Fmktoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkdoc%2Fmktoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkdoc%2Fmktoc/lists"}