{"id":22177375,"url":"https://github.com/leisn/markdown-it-toc","last_synced_at":"2025-07-04T19:04:50.393Z","repository":{"id":45042681,"uuid":"272171706","full_name":"leisn/markdown-it-toc","owner":"leisn","description":"Markdown-it plugin to make table of contents, default parse tag [toc],","archived":false,"fork":false,"pushed_at":"2022-01-12T23:06:51.000Z","size":73,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-27T04:37:00.027Z","etag":null,"topics":["markdown","markdown-it","markdown-it-plugin","markdown-it-toc"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/leisn.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":"2020-06-14T09:36:06.000Z","updated_at":"2020-12-28T08:36:17.000Z","dependencies_parsed_at":"2022-09-26T17:30:36.508Z","dependency_job_id":null,"html_url":"https://github.com/leisn/markdown-it-toc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leisn/markdown-it-toc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leisn%2Fmarkdown-it-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leisn%2Fmarkdown-it-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leisn%2Fmarkdown-it-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leisn%2Fmarkdown-it-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leisn","download_url":"https://codeload.github.com/leisn/markdown-it-toc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leisn%2Fmarkdown-it-toc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263603137,"owners_count":23487211,"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":["markdown","markdown-it","markdown-it-plugin","markdown-it-toc"],"created_at":"2024-12-02T08:27:45.043Z","updated_at":"2025-07-04T19:04:50.350Z","avatar_url":"https://github.com/leisn.png","language":"TypeScript","readme":"# @leisn/markdown-it-toc\n\n![GitHub](https://img.shields.io/github/license/leisn/markdown-it-toc) ![npm (scoped)](https://img.shields.io/npm/v/@leisn/markdown-it-toc)\n\nMarkdown-it plugin to make table of contents, default parse tag [toc].\n\n## Installaton\n\n```bash\n$ npm install @leisn/markdown-it-toc\nor\n$ yarn add @leisn/markdown-it-toc\n```\n\n## E.g. default\n\n### Source markdown\n\n```markdown\n[toc]\n# H1-1\n## H2-1\n### H3-1\n# H1-2\n```\n\n### Result document\n\n```html\n\u003cp\u003e\n  \u003cdiv id=\"toc\" class=\"toc-wrapper\"\u003e\n    \u003cul\u003e\n      \u003cli\u003e\n        \u003ca href=\"#toc.1\"\u003e\n          \u003cspan class=\"toc-item-index\"\u003e1\u003c/span\u003e\n          H1-1\n        \u003c/a\u003e\n      \u003c/li\u003e\n      \u003cul\u003e\n        \u003cli\u003e\n          \u003ca href=\"#toc.1-1\"\u003e\n            \u003cspan class=\"toc-item-index\"\u003e1.1\u003c/span\u003e\n            H2-1\n          \u003c/a\u003e\n        \u003c/li\u003e\n        \u003cul\u003e\n          \u003cli\u003e\n            \u003ca href=\"#toc.1-1-1\"\u003e\n              \u003cspan class=\"toc-item-index\"\u003e1.1.1\u003c/span\u003e\n              H3-1\n            \u003c/a\u003e\n          \u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/ul\u003e\n      \u003cli\u003e\n        \u003ca href=\"#toc.2\"\u003e\n          \u003cspan class=\"toc-item-index\"\u003e2\u003c/span\u003e\n          H1-2\n        \u003c/a\u003e\n      \u003c/li\u003e\n     \u003c/ul\u003e\n  \u003c/div\u003e\n\u003c/p\u003e\n\n\u003ch1 id=\"toc.1\" class=\"toc-heading\"\u003e\n  \u003cspan class=\"toc-heading-prefix\"\u003e1\u003c/span\u003e\n  \u003cspan class=\"toc-heading-content\"\u003eH1-1\u003c/span\u003e\n  \u003ca href=\"#toc\" class=\"toc-heading-suffix\"\u003e#\u003c/a\u003e\n\u003c/h1\u003e\n\u003ch2 id=\"toc.1-1\" class=\"toc-heading\"\u003e\n  \u003cspan class=\"toc-heading-prefix\"\u003e1.1\u003c/span\u003e\n  \u003cspan class=\"toc-heading-content\"\u003eH2-1\u003c/span\u003e\n  \u003ca href=\"#toc\" class=\"toc-heading-suffix\"\u003e#\u003c/a\u003e\n\u003c/h2\u003e\n\u003ch3 id=\"toc.1-1-1\" class=\"toc-heading\"\u003e\n  \u003cspan class=\"toc-heading-prefix\"\u003e1.1.1\u003c/span\u003e\n  \u003cspan class=\"toc-heading-content\"\u003eH3-1\u003c/span\u003e\n  \u003ca href=\"#toc\" class=\"toc-heading-suffix\"\u003e#\u003c/a\u003e\n\u003c/h3\u003e\n\u003ch1 id=\"toc.2\" class=\"toc-heading\"\u003e\n  \u003cspan class=\"toc-heading-prefix\"\u003e2\u003c/span\u003e\n  \u003cspan class=\"toc-heading-content\"\u003eH1-2\u003c/span\u003e\n  \u003ca href=\"#toc\" class=\"toc-heading-suffix\"\u003e#\u003c/a\u003e\n\u003c/h1\u003e\n```\n\n## Usage\n\n```javascript\nconst md = require('markdown-it')(mkOpts) .use(require('@leisn/markdown-it-toc'),options);\nconsole.log(md.render('[toc]\\n# h1\\n## h2-1\\n## h2-2'));\n```\n\n## Options\n\n* **tocRegexp?: RegExp**  Regular expression to detect TOC  (default `/\\[toc\\]/im`).\n\n* **tocTag?: string**  Tag for toc root element ( `div` by default ).\n\n* **tocAttrs?: string**  Attributes for toc root element( `id=\"toc\" class=\"toc-wrapper\"` by default ).\n\n* **headingAttrs?: string**  Attributes for headings `h1,h2,h3...` ( `class=\"toc-heading\"` by default )\n\n  ```html\n  --------------------------\n  # h1 title\n  --------------------------\n  \u003ch1 {headingAttrs}\u003e\n  \u003cspan\u003eh1 title\u003c/span\u003e\n  \u003c/h1\u003e\n  ```\n\n* **headingContentAttrs?: string**  Attributes for headings content `span` ( `class=\"toc-heading-content\"` by default )\n\n  ```html\n  --------------------------\n  # headingContent\n  --------------------------\n  \u003ch1\u003e\n  \u003cspan {headingContentAttrs} \u003e headingContent \u003c/span\u003e\n  \u003c/h1\u003e\n  ```\n\n* **getToc?(toc: string): boolean** Get toc result, return false if you don't want it show in the result html document, else return true(default `null`).  `toc` : the result html document\n\n* **getPathId?(info): string** Get id content for forwarding in page,  (e.g. for `info.paths=[1,2]` default return `toc-no.1-2` )\n\n* **getTocItemContent?(info): string** Content inside toc item `a` (html, include item heading text)\n\n* **getHeadingPrefix?(info): string** Content inside heading (html, before heading text)\n\n  ```html\n  --------------------------\n  # h1 title\n  --------------------------\n  \u003ch1\u003e\n  {getHeadingPrefix}\n  \u003cspan\u003eh1 title\u003c/span\u003e\n  \u003c/h1\u003e\n  ```\n\n* **getHeadingSuffix?(info): string** Content inside heading (html, after heading text)\n\n  ```html\n  --------------------------\n  # h1 title\n  --------------------------\n  \u003ch1\u003e\n  \u003cspan\u003eh1 title\u003c/span\u003e\n  {getHeadingSuffix}\n  \u003c/h1\u003e\n  ```\n\n## Test\n\n```bash\n$ npm run test\nor\n$ yarn test\n```\n\n## LICENSE\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleisn%2Fmarkdown-it-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleisn%2Fmarkdown-it-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleisn%2Fmarkdown-it-toc/lists"}