{"id":20935125,"url":"https://github.com/ahungrynoob/showdown-toc","last_synced_at":"2025-05-13T20:32:25.476Z","repository":{"id":57358928,"uuid":"221671610","full_name":"ahungrynoob/showdown-toc","owner":"ahungrynoob","description":"A markdown table of contents extension for showdown.","archived":false,"fork":false,"pushed_at":"2024-04-11T12:11:10.000Z","size":20,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T03:48:10.627Z","etag":null,"topics":["markdown","showdown","showdown-extension","table-of-content","toc"],"latest_commit_sha":null,"homepage":"","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/ahungrynoob.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-11-14T10:32:46.000Z","updated_at":"2025-01-20T07:30:16.000Z","dependencies_parsed_at":"2024-06-19T22:46:38.523Z","dependency_job_id":"365f934b-e16a-48ea-a73c-0f7008f0aa78","html_url":"https://github.com/ahungrynoob/showdown-toc","commit_stats":{"total_commits":9,"total_committers":2,"mean_commits":4.5,"dds":"0.11111111111111116","last_synced_commit":"e276e368f7d41ec9cd4a60c2d34aa0af8a6ba5c3"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahungrynoob%2Fshowdown-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahungrynoob%2Fshowdown-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahungrynoob%2Fshowdown-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahungrynoob%2Fshowdown-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahungrynoob","download_url":"https://codeload.github.com/ahungrynoob/showdown-toc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254021220,"owners_count":22000885,"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","showdown","showdown-extension","table-of-content","toc"],"created_at":"2024-11-18T22:13:07.289Z","updated_at":"2025-05-13T20:32:25.192Z","avatar_url":"https://github.com/ahungrynoob.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# showdown-toc\n\n[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/showdown-toc.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/showdown-toc\n[travis-image]: https://img.shields.io/travis/ahungrynoob/showdown-toc.svg?style=flat-square\n[travis-url]: https://travis-ci.org/ahungrynoob/showdown-toc\n[codecov-image]: https://codecov.io/gh/ahungrynoob/showdown-toc/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/ahungrynoob/showdown-toc\n[download-image]: https://img.shields.io/npm/dm/showdown-toc.svg?style=flat-square\n[download-url]: https://npmjs.org/package/showdown-toc\n\nA markdown-toc extension for [showdown](https://github.com/showdownjs/showdown).\n\u003cbr/\u003e\n**Features:**\n- export table of contents info through closure\n- output table of contents into your html string\n\n---\n\n## Install\n\n### esm\n```bash\n$ npm i showdown-toc --save\n```\n\n### umd\n```html\n\u003cscript src=\"showdown.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"//unpkg.com/showdown-toc/dist/index.umd.min.js\"\u003e\u003c/script\u003e \n```\n\n## Usage\n\n### 1. export toc info through closure\n```javascript\nimport Showdown from 'showdown';\nimport showdownToc from 'showdown-toc';\n\nconst content = 'your markdown content';\nconst toc = [];\nconst showdown = new Showdown.Converter({ extensions: [showdownToc({ toc })] });\nconst result = showdown.makeHtml(content);\nreturn result;\n```\nThe `toc` array you pass in `showdownToc` will be:\n```javascript\n[\n    { anchor: 'header-1', level: 1, text: 'header 1' }, // # header 1\n    { anchor: 'header-4', level: 4, text: 'header 4' }, // #### header 4\n    ...\n]\n```\n\nThe table of contents will output by default as an ordered list `\u003col\u003e`. You can change this to an unordered list `\u003cul\u003e` by passing in a second parameter of options:\n\n```javascript\nconst content = 'your markdown content';\nconst toc = [];\nconst opts = { listType: 'ul' };\nconst showdown = new Showdown.Converter({ extensions: [showdownToc({ toc, opts })] });\nconst result = showdown.makeHtml(content);\nreturn result;\n```\n\n### 2. output table of contents into your html string\nIn your markdown just put a [toc] where you want a Table of Contents to appear. This extension will look for the first header after the [toc] and use whatever it finds first as the element for the rest of the TOC.\n\nYou can have multiple [toc] in a file, each one will show a Table of Contents for headers after it (and before the next [toc]).\n\nIf you move up a level from the headers being used for a [toc], the Table of Contents will stop (the assumption being you're \"outside\" of that section).\n\n#### example\n\n**Markdown Input**\n\n```markdown\n# Main Page Heading\nThis is the intro to the main page.\n\n## Section 1\nA story.\n\n[toc]\n\n### Part 1\nIt was a nice day.\n\n### Part 2\nThere were stormy clouds on the horizon.\n\n#### Part 2A\nThey were very dark.\n\n### Part 3\nThen it rained.\n\n## Section 2\nNotice the section 2 header above is not included in the TOC of section 1? That's \nbecause each toc tag assumes it should stay in it's own section.\n\n[toc]\n\n### Part 1\n\n### Part 2\n\n#### Part 2A\nNotice this heading isn't in the contents above. We only index the top level \nheadings in each section, to keep things tidy. You may or may not like this, but \nthat's the way it is. If you want to create a pull request with an option, \nyou're welcome to! :)\n\n### Part 3\n\nThe End.\n```\n\n**HTML Output**\n\n\u003e \u003ch1 id=\"mainpageheading\"\u003eMain Page Heading\u003c/h1\u003e\n\u003e \u003cp\u003eThis is the intro to the main page.\u003c/p\u003e\n\u003e \u003ch2 id=\"section1\"\u003eSection 1\u003c/h2\u003e\n\u003e \u003cp\u003eA story.\u003c/p\u003e\n\u003e \u003col class=\"showdown-toc\"\u003e\u003cli\u003e\u003ca href=\"#part1\"\u003ePart 1\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"#part2\"\u003ePart 2\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"#part3\"\u003ePart 3\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e\n\u003e \u003ch3 id=\"part1\"\u003ePart 1\u003c/h3\u003e\n\u003e \u003cp\u003eIt was a nice day.\u003c/p\u003e\n\u003e \u003ch3 id=\"part2\"\u003ePart 2\u003c/h3\u003e\n\u003e \u003cp\u003eThere were stormy clouds on the horizon.\u003c/p\u003e\n\u003e \u003ch4 id=\"part2a\"\u003ePart 2A\u003c/h4\u003e\n\u003e \u003cp\u003eThey were very dark.\u003c/p\u003e\n\u003e \u003ch3 id=\"part3\"\u003ePart 3\u003c/h3\u003e\n\u003e \u003cp\u003eThen it rained.\u003c/p\u003e\n\u003e \u003ch2 id=\"section2\"\u003eSection 2\u003c/h2\u003e\n\u003e \u003cp\u003eNotice the section 2 header above is not included in the TOC of section 1? That's because each toc tag assumes it should stay in it's own section.\u003c/p\u003e\n\u003e \u003col class=\"showdown-toc\"\u003e\u003cli\u003e\u003ca href=\"#part1\"\u003ePart 1\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"#part2\"\u003ePart 2\u003c/a\u003e\u003c/li\u003e\u003cli\u003e\u003ca href=\"#part3\"\u003ePart 3\u003c/a\u003e\u003c/li\u003e\u003c/ol\u003e\n\u003e \u003ch3 id=\"part1\"\u003ePart 1\u003c/h3\u003e\n\u003e \u003ch3 id=\"part2\"\u003ePart 2\u003c/h3\u003e\n\u003e \u003ch4 id=\"part2a\"\u003ePart 2A\u003c/h4\u003e\n\u003e \u003cp\u003eNotice this heading isn't in the contents above. We only index the top level headings in each section, to keep things tidy. You may or may not like this, but that's the way it is. If you want to create a pull request with an option, you're welcome to! :)\u003c/p\u003e\n\u003e \u003ch3 id=\"part3\"\u003ePart 3\u003c/h3\u003e\n\u003e \u003cp\u003eThe End.\u003c/p\u003e\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahungrynoob%2Fshowdown-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahungrynoob%2Fshowdown-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahungrynoob%2Fshowdown-toc/lists"}