`:
- `'react'` output: `ReactElement | null`
- `'html'` output: `string | null`
- `'tokens'` output: `TokensResult | null`
- Returns `null` while highlighting is in progress.
```
--------------------------------
### Configure Multi-theme Auto-switching
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/INDEX.md
Use an object to define light and dark themes for automatic color scheme switching.
```typescript
{code}
```
--------------------------------
### Implement Real-time Code Highlighting
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/examples.md
Uses a textarea to capture user input and updates the ShikiHighlighter component with a specified delay for performance.
```typescript
import { useState } from 'react';
import ShikiHighlighter from 'react-shiki';
export function LiveEditorExample() {
const [code, setCode] = useState(
`function hello() {
console.log("Hello!");
}`
);
return (
);
}
```
--------------------------------
### Configure light-dark() theme switching
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/migration-guide.md
Use light-dark() in defaultColor for automatic theme switching based on system preferences.
```jsx
// Old way (still works)
// New way (recommended)
```
--------------------------------
### Multi-theme with Reactive CSS
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/api-reference/ShikiHighlighter.md
Configure light and dark themes with a default color mode.
```typescript
{code.trim()}
```
--------------------------------
### Implement Multi-theme Support
Source: https://github.com/avgvstvs96/react-shiki/blob/main/playground/src/Demo.mdx
Provides different themes based on the application's color mode.
```tsx
{code.trim()}
```
--------------------------------
### Create a syntax highlighting component for react-markdown
Source: https://github.com/avgvstvs96/react-shiki/blob/main/README.md
Define a custom component to handle code blocks using ShikiHighlighter and the isInlineCode helper.
```tsx
import ReactMarkdown from "react-markdown";
import ShikiHighlighter, { isInlineCode } from "react-shiki";
const CodeHighlight = ({ className, children, node, ...props }) => {
const code = String(children).trim();
const match = className?.match(/language-(\w+)/);
const language = match ? match[1] : undefined;
const isInline = node ? isInlineCode(node) : undefined;
return !isInline ? (
{code}
) : (
{code}
);
};
```
--------------------------------
### Import Web Bundle
Source: https://github.com/avgvstvs96/react-shiki/blob/main/package/README.md
Imports the web-focused bundle containing common languages.
```tsx
import ShikiHighlighter from 'react-shiki/web';
```
--------------------------------
### Project Directory Structure
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/README.md
Visual representation of the source code organization within the package.
```text
package/src/
├── index.ts # Full bundle entry point
├── web.ts # Web bundle entry point
├── core.ts # Core bundle entry point
├── bundles/
│ ├── full.ts # Full bundle factory
│ ├── web.ts # Web bundle factory
│ └── core.ts # Core bundle validation
├── lib/
│ ├── component.tsx # ShikiHighlighter component
│ ├── hook.ts # useShikiHighlighter hook
│ ├── types.ts # Type definitions
│ ├── theme.ts # Theme resolution
│ ├── language.ts # Language resolution
│ ├── options.ts # Options building
│ ├── transformers.ts # Line number transformers
│ ├── plugins.ts # react-markdown integration
│ └── utils.ts # Utilities
└── styles/
├── component.css # Component styles
└── features.css # Line numbers & highlights
```
--------------------------------
### Configure RegExp Engine
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/configuration.md
Use the JavaScript engine to reduce bundle size or enable forgiving mode for parsing.
```typescript
import { createJavaScriptRegexEngine } from 'react-shiki';
// Use JavaScript engine for smaller bundle
{code}
```
```typescript
// JavaScript engine with forgiving mode
import { createJavaScriptRegexEngine } from 'react-shiki';
{code}
```
--------------------------------
### Configuring Engines for Core Bundle
Source: https://github.com/avgvstvs96/react-shiki/blob/main/README.md
Explicitly define an engine when using the minimal core bundle.
```tsx
import {
createHighlighterCore,
createOnigurumaEngine,
createJavaScriptRegexEngine
} from 'react-shiki/core';
const highlighter = await createHighlighterCore({
themes: [import('@shikijs/themes/nord')],
langs: [import('@shikijs/langs/typescript')],
engine: createJavaScriptRegexEngine() // or createOnigurumaEngine(import('shiki/wasm'))
});
```
--------------------------------
### Configure useShikiHighlighter hook
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/configuration.md
Basic structure for passing options to the useShikiHighlighter hook.
```typescript
const highlighted = useShikiHighlighter(
code,
language,
theme,
{
// Options here
}
);
```
--------------------------------
### Define Themes Configuration
Source: https://github.com/avgvstvs96/react-shiki/blob/main/_autodocs/types.md
Defines the structure for mapping theme keys to theme configurations.
```typescript
type Themes = {
[Key in MultiThemeKey]: Theme;
};
type MultiThemeKey = 'dark' | 'light' | (string & {});
```