You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: rename css layer from base to react-shiki (#169)
tailwind v3 reserves @layer base in its postcss plugin, so our css failed
to compile in tailwind v3 apps. a dedicated layer name passes through
untouched and keeps the same cascade behavior.
Fix: rename the CSS cascade layer from `base` to `react-shiki`. Tailwind v3's PostCSS plugin reserves `@layer base` as a directive, so react-shiki's CSS failed to compile in Tailwind v3 apps. A dedicated layer name passes through untouched.
6
+
7
+
If you rely on layer ordering (e.g. overriding react-shiki defaults with Tailwind v4 utilities), declare the order in your stylesheet: `@layer react-shiki, theme, base, components, utilities;`
|`language`|`string \| object`| - | Language to highlight, built-in or custom textmate grammer object |
216
-
|`theme`|`string \| object`|`'github-dark'`| Single or multi-theme configuration, built-in or custom textmate theme object |
212
+
|`language`|`string \| object`| - | Language to highlight, built-in or custom TextMate grammar object |
213
+
|`theme`|`string \| object`|`'github-dark'`| Single or multi-theme configuration, built-in or custom TextMate theme object |
217
214
|`delay`|`number`|`0`| Delay between highlights (in milliseconds) |
218
215
|`customLanguages`|`array`|`[]`|**Deprecated**: use `preloadLanguages` instead. |
219
216
|`preloadLanguages`|`array`|`[]`| Preload bundled language IDs and custom language grammars |
@@ -227,7 +224,7 @@ See [Shiki - RegExp Engines](https://shiki.style/guide/regex-engines) for more i
227
224
|`outputFormat`|`string`|`'react'`| Output format: 'react' for React nodes, 'html' for HTML string |
228
225
|`tabindex`|`number`|`0`| Tab index for the code block |
229
226
|`decorations`|`array`|`[]`| Custom decorations to wrap the highlighted tokens with |
230
-
|`structure`|`string`|`classic`| The structure of the generated HAST and HTML - `classic` or `inline`|
227
+
|`structure`|`string`|`'classic'`| The structure of the generated HAST and HTML - `classic` or `inline`|
231
228
|[`codeToHastOptions`](https://github.com/shikijs/shiki/blob/main/packages/types/src/options.ts#L121)| - | - | All other options supported by Shiki's `codeToHast`|
232
229
233
230
### Component-specific Props
@@ -246,7 +243,7 @@ The `ShikiHighlighter` component offers minimal built-in styling and customizati
246
243
247
244
### Embedded Language Highlighting
248
245
249
-
react-shiki uses Shiki's [`guessEmbeddedLanguages`](https://shiki.style) to automatically detect, load, and highlight languages nested inside other languages — for example, a TypeScript fenced code block inside a Markdown document will be highlighted as TypeScript without any extra configuration. Embedded languages are dynamically loaded on demand, as long as they exist in your bundle.
246
+
react-shiki uses Shiki's [`guessEmbeddedLanguages`](https://github.com/shikijs/shiki/blob/main/packages/core/src/utils/strings.ts) to automatically detect, load, and highlight languages nested inside other languages. For example, a TypeScript fenced code block inside a Markdown document will be highlighted as TypeScript without any extra configuration. Embedded languages are dynamically loaded on demand, as long as they exist in your bundle.
250
247
251
248
### Multi-theme Support
252
249
@@ -337,7 +334,7 @@ For broader browser support or more control, add CSS snippets to your site to en
337
334
338
335
### Custom Themes
339
336
340
-
Custom themes can be passed as a TextMate theme in JavaScript object. For example, [it should look like this](https://github.com/antfu/textmate-grammars-themes/blob/main/packages/tm-themes/themes/dark-plus.json).
337
+
Custom themes can be passed as a TextMate theme JavaScript object ([example](https://github.com/antfu/textmate-grammars-themes/blob/main/packages/tm-themes/themes/dark-plus.json)).
Custom languages should be passed as a TextMate grammar in JavaScript object. For example, [it should look like this](https://github.com/shikijs/textmate-grammars-themes/blob/main/packages/tm-grammars/grammars/typescript.json)
353
+
Custom languages should be passed as a TextMate grammar JavaScript object ([example](https://github.com/shikijs/textmate-grammars-themes/blob/main/packages/tm-grammars/grammars/typescript.json)).
> When using the hook with line numbers, import the CSS file or provide your own CSS
465
-
> for `.rs-line-number` (line `span`) and `.rs-has-line-numbers` (container `code` element).<!-- TODO: The CSS vars/classes/selectors are poorly documented -->
452
+
> for `.rs-line-number` (line `span`) and `.rs-has-line-numbers` (container `code` element).
466
453
> ```tsx
467
454
>import'react-shiki/css';
468
455
>```
469
456
470
-
> [!WARNING]
471
-
> Legacy `.line-numbers` / `.has-line-numbers` selectors and unprefixed line-number CSS variables are removed as of 0.10.1.
457
+
Component-internal default classes are namespaced under `rs-*` and shipped inside the `@layerreact-shiki` cascade layer, so unlayered app CSS and later layers take precedence over them. To control precedence explicitly, declare the layer order at the top of your stylesheet:
472
458
473
-
Component-internal default classes are namespaced under `rs-*` and shipped inside `@layerbase` so app-level utilities can override them more predictably.
Choose HTML output when performance is critical and you trust the code source. Use the default React output when handling untrusted content or when security is the primary concern.
656
+
The two formats spend their rendering work in different phases. HTML output skips per-token React element creation and reconciliation, reducing render-phase overhead for large, one-shot highlights, but each update replaces the code block's entire DOM subtree via `innerHTML`. React output pays for element creation and diffing on every update, but commits only incremental DOM mutations, minimizing DOM churn for frequently re-highlighted code such as streaming LLM output.
657
+
658
+
HTML output hands the highlighted markup to the DOM via `dangerouslySetInnerHTML`, so only use it with trusted code sources. The default React output is the safe choice for untrusted content.
0 commit comments