{"id":13483617,"url":"https://github.com/rehypejs/rehype-slug","last_synced_at":"2025-03-27T14:31:25.348Z","repository":{"id":45221278,"uuid":"71638543","full_name":"rehypejs/rehype-slug","owner":"rehypejs","description":"plugin to add `id` attributes to headings","archived":false,"fork":false,"pushed_at":"2023-08-31T14:06:00.000Z","size":79,"stargazers_count":178,"open_issues_count":0,"forks_count":7,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-04-26T17:44:36.040Z","etag":null,"topics":["heading","html","rehype","rehype-plugin","slug"],"latest_commit_sha":null,"homepage":"https://unifiedjs.com","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/rehypejs.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},"funding":{"github":"unifiedjs","open_collective":"unified"}},"created_at":"2016-10-22T12:46:25.000Z","updated_at":"2024-05-31T22:54:23.961Z","dependencies_parsed_at":"2024-05-31T23:04:18.576Z","dependency_job_id":null,"html_url":"https://github.com/rehypejs/rehype-slug","commit_stats":{"total_commits":84,"total_committers":4,"mean_commits":21.0,"dds":0.04761904761904767,"last_synced_commit":"1c61632f1526c6b59c80530ed334d4a094c7a091"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-slug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-slug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-slug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rehypejs%2Frehype-slug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rehypejs","download_url":"https://codeload.github.com/rehypejs/rehype-slug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245863098,"owners_count":20684788,"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":["heading","html","rehype","rehype-plugin","slug"],"created_at":"2024-07-31T17:01:13.353Z","updated_at":"2025-03-27T14:31:25.044Z","avatar_url":"https://github.com/rehypejs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/unifiedjs","https://opencollective.com/unified"],"categories":["JavaScript"],"sub_categories":[],"readme":"# rehype-slug\n\n[![Build][build-badge]][build]\n[![Coverage][coverage-badge]][coverage]\n[![Downloads][downloads-badge]][downloads]\n[![Size][size-badge]][size]\n[![Sponsors][sponsors-badge]][collective]\n[![Backers][backers-badge]][collective]\n[![Chat][chat-badge]][chat]\n\n**[rehype][]** plugin to add `id`s to headings.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`unified().use(rehypeSlug[, options])`](#unifieduserehypeslug-options)\n    *   [`Options`](#options)\n*   [Types](#types)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Related](#related)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package is a [unified][] ([rehype][]) plugin to add `id`s to headings.\nIt looks for headings (so `\u003ch1\u003e` through `\u003ch6\u003e`) that do not yet have `id`s\nand adds `id` attributes to them based on the text they contain.\nThe algorithm that does this is [`github-slugger`][github-slugger], which\nmatches how GitHub works.\n\n**unified** is a project that transforms content with abstract syntax trees\n(ASTs).\n**rehype** adds support for HTML to unified.\n**hast** is the HTML AST that rehype uses.\nThis is a rehype plugin that adds `id`s to headings in the AST.\n\n## When should I use this?\n\nThis plugin is useful when you have relatively long documents and you want to be\nable to link to particular sections.\n\nA different plugin, [`rehype-autolink-headings`][rehype-autolink-headings], adds\nlinks to these headings back to themselves, which is useful as it lets users\nmore easily link to particular sections.\n\n## Install\n\nThis package is [ESM only][esm].\nIn Node.js (version 16+), install with [npm][]:\n\n```sh\nnpm install rehype-slug\n```\n\nIn Deno with [`esm.sh`][esmsh]:\n\n```js\nimport rehypeSlug from 'https://esm.sh/rehype-slug@6'\n```\n\nIn browsers with [`esm.sh`][esmsh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import rehypeSlug from 'https://esm.sh/rehype-slug@6?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay we have the following file `example.html`:\n\n```html\n\u003ch1 id=some-id\u003eLorem ipsum\u003c/h1\u003e\n\u003ch2\u003eDolor sit amet 😪\u003c/h2\u003e\n\u003ch3\u003econsectetur \u0026amp; adipisicing\u003c/h3\u003e\n\u003ch4\u003eelit\u003c/h4\u003e\n\u003ch5\u003eelit\u003c/h5\u003e\n```\n\n…and our module `example.js` looks as follows:\n\n```js\nimport {read} from 'to-vfile'\nimport {rehype} from 'rehype'\nimport rehypeSlug from 'rehype-slug'\n\nconst file = await rehype()\n  .data('settings', {fragment: true})\n  .use(rehypeSlug)\n  .process(await read('example.html'))\n\nconsole.log(String(file))\n```\n\n…then running `node example.js` yields:\n\n```html\n\u003ch1 id=\"some-id\"\u003eLorem ipsum\u003c/h1\u003e\n\u003ch2 id=\"dolor-sit-amet-\"\u003eDolor sit amet 😪\u003c/h2\u003e\n\u003ch3 id=\"consectetur--adipisicing\"\u003econsectetur \u0026#x26; adipisicing\u003c/h3\u003e\n\u003ch4 id=\"elit\"\u003eelit\u003c/h4\u003e\n\u003ch5 id=\"elit-1\"\u003eelit\u003c/h5\u003e\n```\n\n## API\n\nThis package exports no identifiers.\nThe default export is [`rehypeSlug`][api-rehype-slug].\n\n### `unified().use(rehypeSlug[, options])`\n\nAdd `id`s to headings.\n\n###### Parameters\n\n*   `options` ([`Options`][api-options], optional)\n    — configuration\n\n###### Returns\n\nTransform ([`Transformer`][unified-transformer]).\n\n### `Options`\n\nConfiguration (TypeScript type).\n\n###### Fields\n\n*   `prefix` (`string`, default: `''`)\n    — prefix to add in front of `id`s\n\n## Types\n\nThis package is fully typed with [TypeScript][].\nIt exports the additional type [`Options`][api-options].\n\n## Compatibility\n\nProjects maintained by the unified collective are compatible with maintained\nversions of Node.js.\n\nWhen we cut a new major release, we drop support for unmaintained versions of\nNode.\nThis means we try to keep the current release line, `rehype-slug@^6`,\ncompatible with Node.js 16.\n\nThis plugin works with `rehype-parse` version 1+, `rehype-stringify` version 1+,\n`rehype` version 1+, and `unified` version 4+.\n\n## Security\n\nUse of `rehype-slug` can open you up to a [cross-site scripting (XSS)][xss]\nattack as it sets `id` attributes on headings, which causes what is known\nas “DOM clobbering”.\nPlease use [`rehype-sanitize`][rehype-sanitize] and see its\n[Example: headings (DOM clobbering)][rehype-sanitize-example] for information on\nhow to properly solve it.\n\n## Related\n\n*   [`rehype-autolink-headings`][rehype-autolink-headings]\n    — add links to headings with IDs back to themselves\n\n## Contribute\n\nSee [`contributing.md`][contributing] in [`rehypejs/.github`][health] for ways\nto get started.\nSee [`support.md`][support] for ways to get help.\n\nThis project has a [code of conduct][coc].\nBy interacting with this repository, organization, or community you agree to\nabide by its terms.\n\n## License\n\n[MIT][license] © [Titus Wormer][author]\n\n\u003c!-- Definitions --\u003e\n\n[build-badge]: https://github.com/rehypejs/rehype-slug/workflows/main/badge.svg\n\n[build]: https://github.com/rehypejs/rehype-slug/actions\n\n[coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype-slug.svg\n\n[coverage]: https://codecov.io/github/rehypejs/rehype-slug\n\n[downloads-badge]: https://img.shields.io/npm/dm/rehype-slug.svg\n\n[downloads]: https://www.npmjs.com/package/rehype-slug\n\n[size-badge]: https://img.shields.io/bundlejs/size/rehype-slug\n\n[size]: https://bundlejs.com/?q=rehype-slug\n\n[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg\n\n[backers-badge]: https://opencollective.com/unified/backers/badge.svg\n\n[collective]: https://opencollective.com/unified\n\n[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg\n\n[chat]: https://github.com/rehypejs/rehype/discussions\n\n[npm]: https://docs.npmjs.com/cli/install\n\n[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[esmsh]: https://esm.sh\n\n[health]: https://github.com/rehypejs/.github\n\n[contributing]: https://github.com/rehypejs/.github/blob/main/contributing.md\n\n[support]: https://github.com/rehypejs/.github/blob/main/support.md\n\n[coc]: https://github.com/rehypejs/.github/blob/main/code-of-conduct.md\n\n[license]: license\n\n[author]: https://wooorm.com\n\n[github-slugger]: https://github.com/Flet/github-slugger\n\n[rehype]: https://github.com/rehypejs/rehype\n\n[rehype-autolink-headings]: https://github.com/rehypejs/rehype-autolink-headings\n\n[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize\n\n[rehype-sanitize-example]: https://github.com/rehypejs/rehype-sanitize#example-headings-dom-clobbering\n\n[typescript]: https://www.typescriptlang.org\n\n[unified]: https://github.com/unifiedjs/unified\n\n[unified-transformer]: https://github.com/unifiedjs/unified#transformer\n\n[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting\n\n[api-options]: #options\n\n[api-rehype-slug]: #unifieduserehypeslug-options\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehypejs%2Frehype-slug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frehypejs%2Frehype-slug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehypejs%2Frehype-slug/lists"}