{"id":22249368,"url":"https://github.com/penge/toc-to-html","last_synced_at":"2026-04-19T05:37:11.566Z","repository":{"id":35162261,"uuid":"215804307","full_name":"penge/toc-to-html","owner":"penge","description":"NPM package that changes TOC from a flat JSON array to an HTML string.","archived":false,"fork":false,"pushed_at":"2023-01-04T22:53:35.000Z","size":277,"stargazers_count":2,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T12:14:31.872Z","etag":null,"topics":["npm-package","table-of-content","table-of-contents","toc"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/penge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-17T13:50:57.000Z","updated_at":"2023-01-31T17:38:41.000Z","dependencies_parsed_at":"2023-01-15T15:02:47.693Z","dependency_job_id":null,"html_url":"https://github.com/penge/toc-to-html","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/penge/toc-to-html","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penge%2Ftoc-to-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penge%2Ftoc-to-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penge%2Ftoc-to-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penge%2Ftoc-to-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/penge","download_url":"https://codeload.github.com/penge/toc-to-html/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/penge%2Ftoc-to-html/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268623981,"owners_count":24280145,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["npm-package","table-of-content","table-of-contents","toc"],"created_at":"2024-12-03T06:26:21.027Z","updated_at":"2026-04-19T05:37:11.532Z","avatar_url":"https://github.com/penge.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# toc-to-html\n\n`toc-to-html` can change one-level array `toc` (table of contents)\nto a nested `html` list.\n\n## Example toc\n\nLet's say we have `toc` that looks like this:\n\n```js\nconst toc = [\n  {\n    content: 'Coffee',\n    slug: 'coffee',\n    lvl: 2\n  },\n  {\n    content: 'Tea',\n    slug: 'tea',\n    lvl: 2\n  },\n  {\n    content: 'Black tea',\n    slug: 'black-tea',\n    lvl: 3\n  },\n  {\n    content: 'Green tea',\n    slug: 'green-tea',\n    lvl: 3\n  },\n  {\n    content: 'Milk',\n    slug: 'milk',\n    lvl: 2\n  }\n];\n```\n\n`toc` can be created by `markdown-toc`\nor other if following same structure.\n\n## Example html\n\nThe `html` we get:\n\n```html\n\u003cul\u003e\n  \u003cli\u003e\u003ca href=\"#coffee\"\u003eCoffee\u003c/a\u003e\u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#tea\"\u003eTea\u003c/a\u003e\n    \u003cul\u003e\n      \u003cli\u003e\u003ca href=\"#black-tea\"\u003eBlack tea\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"#green-tea\"\u003eGreen tea\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/li\u003e\n  \u003cli\u003e\u003ca href=\"#milk\"\u003eMilk\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n```\n\n## How to use\n\n```js\nconst tocToHtml = require('toc-to-html');\nconst toc = [\n  /* as above toc */\n];\n\n/* change toc to html */\nconst html = tocToHtml(toc, /* options */);\n\n/* see html */\nconsole.log(html);\n```\n\n### `options`\n\n```js\n// ...\nconst options = {\n  id: 'toc-list', // is optional\n  clazz: 'list' // is optional\n};\n\nconst html = tocToHtml(toc, options);\n```\n\n```html\n\u003cul id=\"toc-list\" class=\"list\"\u003e\n  \u003c!-- items --\u003e\n\u003c/ul\u003e\n```\n\n## When to use\n\n- when putting `\u003c!-- toc --\u003e` into every\nmarkdown file to inject the HTML at that position\ntakes too much time and also is nightmare\nto change the position later as every file\nneeds to be updated\n\n- when you need full control over where you put\nthe HTML by using a template library\n(pug, ejs, handlebars, mustache, or other)\nand passing the HTML via data\n\n- when the HTML list created by a compiler\n(marked, markdown-it, remarkable, showdown, or other)\ndoesn't have `id` or `class` but you need that control\nor more versatility\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenge%2Ftoc-to-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpenge%2Ftoc-to-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpenge%2Ftoc-to-html/lists"}