Skip to content

Commit

Permalink
feat: add code highlighting (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
EehMauro authored Nov 28, 2024
1 parent 28c1aba commit 79d3d06
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 549 deletions.
140 changes: 140 additions & 0 deletions frontend/package-lock.json

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

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"next-mdx-remote": "^5.0.0",
"react": "^18",
"react-dom": "^18",
"shiki": "^1.23.1",
"zustand": "^5.0.1"
},
"devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/CodeBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client";

import { useEffect, useState } from "react";
import { codeToHtml } from "shiki";

const CodeBlock = ({
content,
}: {
content: string;
}) => {
const [code, setCode] = useState<string>('<div></div>');

useEffect(() => {
codeToHtml(content, { lang: 'typescript', theme: 'dark-plus' }).then(setCode);
}, [content]);

return <div dangerouslySetInnerHTML={{ __html: code }} />;
}

export default CodeBlock;
Loading

0 comments on commit 79d3d06

Please sign in to comment.