Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 10, 2024
1 parent da2d7da commit 0cd190a
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions docs/packages/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ Serverless Runtime is recommended.
Since Server Components are server-only, you can use the bundled highlighter without worrying the bundle size.

```tsx
import { type BundledLanguage, codeToHtml } from 'shiki'
import type { BundledLanguage } from 'shiki'
import { codeToHtml } from 'shiki'

export default function Page() {
return (
<main>
<CodeBlock lang="ts">
{`
console.log("Hello")
console.log("World")
`}
{[
'console.log("Hello")',
'console.log("World")',
].join('\n')}
</CodeBlock>
</main>
)
Expand All @@ -48,19 +49,20 @@ async function CodeBlock(props: Props) {
You can also call `codeToHast` to get the HTML abstract syntax tree, and render it using [`hast-util-to-jsx-runtime`](https://github.com/syntax-tree/hast-util-to-jsx-runtime). With this method, you can render your own `pre` and `code` components.

```tsx
import type { BundledLanguage } from 'shiki'
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
import { Fragment } from 'react'
import { jsx, jsxs } from 'react/jsx-runtime'
import { type BundledLanguage, codeToHast } from 'shiki'
import { codeToHast } from 'shiki'

export default function Page() {
return (
<main>
<CodeBlock lang="ts">
{`
console.log("Hello")
console.log("World")
`}
{[
'console.log("Hello")',
'console.log("World")',
].join('\n')}
</CodeBlock>
</main>
)
Expand Down Expand Up @@ -97,10 +99,11 @@ We can start by creating a client `CodeBlock` component.
Create a `shared.ts` for highlighter:

```ts
import type { BundledLanguage } from 'shiki/bundle/web'
import { toJsxRuntime } from 'hast-util-to-jsx-runtime'
import { Fragment } from 'react'
import { jsx, jsxs } from 'react/jsx-runtime'
import { type BundledLanguage, codeToHast } from 'shiki/bundle/web'
import { codeToHast } from 'shiki/bundle/web'

export async function highlight(code: string, lang: BundledLanguage) {
const out = await codeToHast(code, {
Expand Down

0 comments on commit 0cd190a

Please sign in to comment.