{"id":16859508,"url":"https://github.com/cowboy/node-toc","last_synced_at":"2025-03-22T06:31:27.892Z","repository":{"id":7315184,"uuid":"8633421","full_name":"cowboy/node-toc","owner":"cowboy","description":"Linkify HTML headers and generate a TOC.","archived":false,"fork":false,"pushed_at":"2014-02-28T21:01:00.000Z","size":168,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T17:06:46.116Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cowboy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-07T18:10:08.000Z","updated_at":"2025-02-10T05:47:48.000Z","dependencies_parsed_at":"2022-09-26T16:21:52.565Z","dependency_job_id":null,"html_url":"https://github.com/cowboy/node-toc","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowboy%2Fnode-toc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowboy%2Fnode-toc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowboy%2Fnode-toc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cowboy%2Fnode-toc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cowboy","download_url":"https://codeload.github.com/cowboy/node-toc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244918500,"owners_count":20531682,"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-10-13T14:18:03.995Z","updated_at":"2025-03-22T06:31:25.974Z","avatar_url":"https://github.com/cowboy.png","language":"JavaScript","readme":"# toc [![Build Status](https://secure.travis-ci.org/cowboy/node-toc.png?branch=master)](http://travis-ci.org/cowboy/node-toc)\n\nLinkify HTML headers and generate a TOC.\n\n## Getting Started\nInstall the module with: `npm install toc`\n\n```js\nvar toc = require('toc');\n```\n\n## Documentation\n\n### toc.untag\nStrip HTML tags from a string.\n\n```js\nvar stripped = toc.untag(html);\n```\n\n### toc.anchor\nConvert a string of text into something URL-friendly and not too fugly.\n\n```js\nvar anchor = toc.anchor(arbitraryText);\n```\n\n\n### toc.unique\nGet a unique name and store the returned name in names for future unique-name-gettingness.\n\n```js\nvar names = {};\nvar guaranteedUniqueAnchor1 = toc.unique(names, toc.anchor(arbitraryText));\nvar guaranteedUniqueAnchor2 = toc.unique(names, toc.anchor(arbitraryText));\n```\n\n\n### toc.process\nAnchorize all headers and inline a generated TOC, returning processed HTML.\n\n```js\nvar htmlWithAnchorsAndTOC = toc.process(html [, options]);\n```\n\n#### options\n\n* **placeholder** - `RegExp` - Used to match TOC placeholder. Defaults to `/\u003c!--\\s*toc\\s*--\u003e/gi`.\n* _Because this method calls the `toc.anchorize` and `toc.toc` methods internally, their options may be specified as well._\n\n\n### toc.anchorize\nParse HTML, returning an array of header objects and anchorized HTML.\n\n```js\nvar obj = toc.anchorize(html [, options]);\n```\n\n#### options\n\n* **headers** - `RegExp` - Used to match HTML headers. Defaults to `/\u003ch(\\d)(\\s*[^\u003e]*)\u003e([\\s\\S]+?)\u003c\\/h\\1\u003e/gi`.\n* **tocMin** - `Number` - Min header level to add to TOC. Defaults to `2`.\n* **tocMax** - `Number` - Max header level to add to TOC. Defaults to `6`.\n* **anchorMin** - `Number` - Min header level to anchorize. Defaults to `2`.\n* **anchorMax** - `Number` - Max header level to anchorize. Defaults to `6`.\n* **header** - `String` | `Function` - Lodash template string or function used to anchorize a header.\n\n\n### toc.toc\nGenerate TOC HTML from an array of header objects.\n\n```js\nvar obj = toc.toc(headers [, options]);\n```\n\n#### options\n\n* **openUL** - `String` | `Function` - Lodash template string or function used to generate the TOC.\n* **closeUL** - `String` | `Function` - Lodash template string or function used to generate the TOC.\n* **openLI** - `String` | `Function` - Lodash template string or function used to generate the TOC.\n* **closeLI** - `String` | `Function` - Lodash template string or function used to generate the TOC.\n* **TOC** - `String` | `Function` - Lodash template string or function used to wrap the generated TOC.\n\n\n## Examples\n\nThe default HTML is pretty awesome, but you can customize the hell out of the generated HTML, eg.\n\n```js\nvar processedHTML = toc.process(unprocessedHTML, {\n  header: '\u003ch\u003c%= level %\u003e\u003c%= attrs %\u003e id=\"\u003c%= anchor %\u003e\"\u003e\u003c%= header %\u003e\u003c/h\u003c%= level %\u003e\u003e',\n  TOC: '\u003cdiv class=\"toc\"\u003e\u003c%= toc %\u003e\u003c/div\u003e',\n  openUL: '\u003cul data-depth=\"\u003c%= depth %\u003e\"\u003e',\n  closeUL: '\u003c/ul\u003e',\n  openLI: '\u003cli data-level=\"H\u003c%= level %\u003e\"\u003e\u003ca href=\"#\u003c%= anchor %\u003e\"\u003e\u003c%= text %\u003e\u003c/a\u003e',\n  closeLI: '\u003c/li\u003e',\n});\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n2014-02-28 - v0.4.0 - Updated a bunch of dependencies. Functionality shouldn't change, and all test pass, but YMMV.  \n2013-03-08 - v0.3.0 - Separated `.process` method internals into `.anchorize` and `.toc` methods. Renamed `toc` template option to `TOC`.  \n2013-03-07 - v0.2.0 - Second official release. Minor changes.  \n2013-03-07 - v0.1.0 - First official release.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcowboy%2Fnode-toc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcowboy%2Fnode-toc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcowboy%2Fnode-toc/lists"}