{"id":18774108,"url":"https://github.com/leafac/rehype-shiki","last_synced_at":"2025-10-25T01:11:56.828Z","repository":{"id":43119435,"uuid":"333140794","full_name":"leafac/rehype-shiki","owner":"leafac","description":"Rehype plugin to highlight code blocks with Shiki","archived":false,"fork":false,"pushed_at":"2023-01-07T22:12:04.000Z","size":283,"stargazers_count":31,"open_issues_count":4,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T07:41:41.123Z","etag":null,"topics":[],"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/leafac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"leafac","custom":["https://paypal.me/LeandroFacchinettiEU","https://btc.com/34KJBgtaFYMtDqpSgMayw9qiKWg2GQXA9M"],"github":"leafac"}},"created_at":"2021-01-26T16:13:25.000Z","updated_at":"2025-02-12T13:03:00.000Z","dependencies_parsed_at":"2023-02-08T02:47:44.886Z","dependency_job_id":null,"html_url":"https://github.com/leafac/rehype-shiki","commit_stats":null,"previous_names":["leafac/shiki-rehype"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafac%2Frehype-shiki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafac%2Frehype-shiki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafac%2Frehype-shiki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafac%2Frehype-shiki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafac","download_url":"https://codeload.github.com/leafac/rehype-shiki/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689374,"owners_count":21145922,"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-11-07T19:37:23.182Z","updated_at":"2025-10-25T01:11:56.775Z","avatar_url":"https://github.com/leafac.png","language":"TypeScript","funding_links":["https://patreon.com/leafac","https://paypal.me/LeandroFacchinettiEU","https://btc.com/34KJBgtaFYMtDqpSgMayw9qiKWg2GQXA9M","https://github.com/sponsors/leafac"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e@leafac/rehype-shiki\u003c/h1\u003e\n\u003ch3 align=\"center\"\u003e\u003ca href=\"https://github.com/rehypejs/rehype\"\u003eRehype\u003c/a\u003e plugin to highlight code blocks with \u003ca href=\"https://shiki.matsu.io\"\u003eShiki\u003c/a\u003e\u003c/h3\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/leafac/rehype-shiki\"\u003e\u003cimg src=\"https://img.shields.io/badge/Source---\" alt=\"Source\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@leafac/rehype-shiki\"\u003e\u003cimg alt=\"Package\" src=\"https://badge.fury.io/js/%40leafac%2Frehype-shiki.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/leafac/rehype-shiki/actions\"\u003e\u003cimg src=\"https://github.com/leafac/rehype-shiki/workflows/.github/workflows/main.yml/badge.svg\" alt=\"Continuous Integration\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n### Installation\n\n```console\n$ npm install @leafac/rehype-shiki shiki\n```\n\n### Format\n\nCode blocks must have the following format:\n\n```html\n\u003cpre\u003e\n\u003ccode class=\"language-javascript\"\u003e\nreturn unified();\n\u003c/code\u003e\n\u003c/pre\u003e\n```\n\nThis is the format produced by [remark-parse](https://github.com/remarkjs/remark/tree/main/packages/remark-parse) \u0026 [remark-rehype](https://github.com/remarkjs/remark-rehype) from the following Markdown:\n\n````markdown\n```javascript\nreturn unified();\n```\n````\n\n### Usage\n\nSee [`source/index.test.ts`](source/index.test.ts) for examples.\n\n#### Options\n\n- `highlighter` (required): An instance of the Shiki highlighter, or an object whose keys are identifiers and values are Shiki highlighters, in which case @leafac/rehype-shiki combines the outputs of all the highlighters.\n- `throwOnUnsupportedLanguage` (default: `false`): A boolean indicating whether to throw an exception if a code block refers to an unsupported language.\n\n### Security\n\n@leafac/rehype-shiki doesn’t open you up to [cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks as long as Shiki doesn’t (which it doesn’t).\n\n### How Is This Different from [rehype-shiki](https://github.com/rsclarke/rehype-shiki)?\n\nrehype-shiki is great! That’s how I learned about Shiki and I fell in love with it. The following are the ways in which @leafac/rehype-shiki is different:\n\n1. TypeScript support.\n2. Shiki is declared as a [`peerDependency`](https://docs.npmjs.com/cli/v6/configuring-npm/package-json#peerdependencies), so @leafac/rehype-shiki doesn’t have to be updated when new versions of Shiki are released (as long as Shiki’s API remain compatible). See https://github.com/rsclarke/rehype-shiki/pull/48 https://github.com/rsclarke/rehype-shiki/pull/46 https://github.com/rsclarke/rehype-shiki/issues/47 https://github.com/rsclarke/rehype-shiki/issues/2.\n3. You must pass in an instance of the Shiki highlighter, @leafac/rehype-shiki won’t create one for you. This means that:\n   1. The Shiki highlighter instance is reused on every invocation of the processor, [instead of being recreated every time you call the processor](https://github.com/rsclarke/rehype-shiki/blob/3ebaeab3297d1cbe9ac75e2294ab636bbe250541/index.js#L38-L43).\n   2. The transformer is synchronous, so you may use it with `.processSync()`.\n4. Instead of [looking at the tokens produced by Shiki and generating hast](https://github.com/rsclarke/rehype-shiki/blob/3ebaeab3297d1cbe9ac75e2294ab636bbe250541/index.js#L69-L97), [@leafac/rehype-shiki lets Shiki produce HTML and parses the result](https://github.com/leafac/rehype-shiki/blob/a745b01d98608fb934c1bdbe9a1399e8b9dec1ed/src/index.ts#L32-L39). The advantage is that [when Shiki improves the output with things like italics](https://github.com/shikijs/shiki/pull/23) @leafac/rehype-shiki will pick the changes up with no extra work. The disadvantage is that we’re producing HTML as a string and then parsing it right back; this is slower, but in most cases it won’t matter and I think the previous advantages outweighs this disadvantage. (Also, the `language-*` class will be removed from the produced HTML, so you may need to adapt your CSS.)\n5. Support for multiple highlighters.\n\nThat said, [I contacted the maintainers of rehype-shiki and try to merge the code bases](https://github.com/rsclarke/rehype-shiki/issues/49). We’ll see…\n\n### Changelog\n\n### 2.2.0\n\n- Updated the peer dependency to `shiki@0.11.1`.\n\n#### 2.1.0\n\n- Added a feature that preserves the `position` of the top `element` node. Useful for products that need to map the HTML back to the Markdown that generated it (see tests).\n\n#### 2.0.0\n\n- [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).\n- Compatible with unified 10.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafac%2Frehype-shiki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafac%2Frehype-shiki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafac%2Frehype-shiki/lists"}