Skip to content

Commit

Permalink
fix: use shiki
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Mar 21, 2024
1 parent 7d083db commit 570f31d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 25 deletions.
20 changes: 0 additions & 20 deletions demo/app/(mdx)/highlighter.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions demo/app/(mdx)/install/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ order: 1
---

# Quick Start

```sh
npm install rc
```
3 changes: 0 additions & 3 deletions demo/app/(mdx)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

import type { PropsWithChildren } from "react"

import { Highlighter } from "./highlighter"

export default ({ children }: PropsWithChildren) => (
<>
<div className="prose dark:prose-invert">{children}</div>
<Highlighter />
</>
)
23 changes: 23 additions & 0 deletions demo/mdx-components.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
import type { MDXComponents } from "mdx/types"
import { getHighlighter } from "shiki"

const highlighter = await getHighlighter({
themes: ["github-dark"],
langs: ["javascript", "typescript", "json", "jsx", "tsx", "shell"],
})

export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
pre: (props) => {
const language =
(props.children as any).props.className?.replace(/language-/, "") ||
"text"

const rawCode = (props.children as any).props.children
return (
<div
dangerouslySetInnerHTML={{
__html: highlighter.codeToHtml(rawCode, {
lang: language,
theme: "github-dark",
}),
}}
></div>
)
},
}
}
1 change: 1 addition & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"remark-frontmatter": "5.0.0",
"remark-mdx-frontmatter": "4.0.0",
"sharp": "^0.33.2",
"shiki": "1.2.0",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.6",
"vaul": "^0.9.0"
Expand Down
3 changes: 2 additions & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"module": "esnext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
Expand Down Expand Up @@ -45,4 +46,4 @@
"exclude": [
"node_modules"
]
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"prebuild": "rm -rf lib && rm -rf esm",
"build": "vite build && tailwindcss -i src/tw.css -o dist/index.css",
"prepare": "husky install",
"release": "bump"
"release": "bump",
"dev": "vite build --watch"
},
"devDependencies": {
"@innei/bump-version": "1.5.10",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 570f31d

Please sign in to comment.