{"id":16095802,"url":"https://github.com/zeusdeux/md-toc","last_synced_at":"2025-03-18T07:30:19.174Z","repository":{"id":149116630,"uuid":"397698637","full_name":"zeusdeux/md-toc","owner":"zeusdeux","description":"Generate a GitHub compatible table of contents from headings in a markdown file. Tie into a pre-commit hook for max level awesome!","archived":false,"fork":false,"pushed_at":"2023-11-29T19:55:29.000Z","size":149,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T17:45:28.019Z","etag":null,"topics":["cli","contents","husky","lint-staged","markdown","pnpm","pre-commit","pre-commit-hook"],"latest_commit_sha":null,"homepage":"","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/zeusdeux.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-18T18:26:12.000Z","updated_at":"2024-05-22T01:18:20.000Z","dependencies_parsed_at":"2024-10-27T17:40:12.178Z","dependency_job_id":null,"html_url":"https://github.com/zeusdeux/md-toc","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"578b19de1d850a0dfbd3735ab46f4ab3693deed4"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fmd-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fmd-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fmd-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fmd-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeusdeux","download_url":"https://codeload.github.com/zeusdeux/md-toc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244177648,"owners_count":20410993,"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":["cli","contents","husky","lint-staged","markdown","pnpm","pre-commit","pre-commit-hook"],"created_at":"2024-10-09T17:08:55.876Z","updated_at":"2025-03-18T07:30:18.764Z","avatar_url":"https://github.com/zeusdeux.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# md-toc\n\nGenerate a GitHub compatible table of contents from headings in a markdown file.\n\n## Table of contents\n\n- [Motivation](#motivation)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Usage with `lint-staged`](#usage-with-lint-staged)\n  - [Usage as a CLI](#usage-as-a-cli)\n- [Debugging](#debugging)\n- [Contributing](#contributing)\n\n## Motivation\n\nI wanted something for myself that does exactly what I need it to do and exposes all the levers that\nI need. Also, I specifically wanted a CLI that can run in a pre-commit hook (via `husky` +\n`lint-staged`) before `prettier --write` for markdown files so that I never have another piece of\ndocumentation without a table of contents!\n\n## Installation\n\n```sh\nnpm install -D @zeusdeux/md-toc\n```\n\n## Usage\n\n### Usage with `lint-staged`\n\nAdd the following line to the `\"lint-staged\"` config\n\n```json\n\"lint-staged\": {\n  \"*.md\": \"md-toc --write\",\n}\n```\n\nIt is recommended that you run `prettier` _after_ `md-toc`. For example —\n\n```json\n\"lint-staged\": {\n  \"*.md\": [\"md-toc --write\", \"prettier --write\"],\n}\n```\n\n### Usage as a CLI\n\n    md-toc\n\n    Usage: $0 [options] \u003cfile or stdin\u003e\n\n    Options:\n      -d, --debug        Print debug logs to stderr                 [boolean] [default: false]\n      -v, --version      Show cli version                                            [boolean]\n      -h, --help         Show help                                                   [boolean]\n      -w, --write        Write changes to the input file            [boolean] [default: false]\n      -a, --insertUnder  Heading to insert the table of contents under. Defaults to table of c\n                         ontents|toc|table-of-contents                  [string] [default: \"\"]\n\n    Examples:\n      md-toc --write Readme.md           Generate a table of contents from headings in Readme.\n                                         md, insert them under a heading name \"Table of Conten\n                                         ts\", \"toc\" or \"table-of-contents\" (all case insensiti\n                                         ve) in Readme.md and write the file to disk.\n      md-toc Readme.md                   Same as the --write option but the output is written\n                                         to stdout and Readme.md is left as is.\n      md-toc -a \"Contents\" -w Readme.md  Same as --write but the table of contents is inserted\n                                          under the first heading named \"Contents\".\n\n## Debugging\n\nIf you run into problems and want to open an issue here, please run the cli with `--debug` and put\nthe output in the issue. Do redact [PII](https://en.wikipedia.org/wiki/Personal_data) from the debug\ninfo before pasting into the issue.\n\n## Contributing\n\nThe package manager used is `pnpm` so please use that and don't commit a `package-lock.json`. Also,\nbefore starting development, run `nvm use` in the folder where you clone this repository.\n\nOther than that, it is a fairly tiny codebase. Feel free to clone, edit and open a PR.\n\nTo test your changes locally, run `pnpm link --global` and assuming you are using `nvm`, this should\nmake `md-toc` available as a command in your shell.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fmd-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeusdeux%2Fmd-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fmd-toc/lists"}