Skip to content

Commit 525340a

Browse files
committed
POC: Parsing markdown and applying styles/components manually without react-markdown
1 parent a3cfc8a commit 525340a

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"class-variance-authority": "^0.7.1",
1818
"clsx": "^2.1.1",
1919
"lucide-react": "^0.548.0",
20+
"mdast-util-from-markdown": "^2.0.2",
2021
"next-themes": "^0.4.6",
2122
"react": "^19.1.1",
2223
"react-dom": "^19.1.1",
23-
"react-markdown": "^10.1.0",
2424
"react-router": "^7.9.4",
2525
"tailwind-merge": "^3.3.1"
2626
},

src/components/libresplit/AppGitHubReadme.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
22

3-
import Markdown from "react-markdown";
3+
import { MarkdownToJSX } from "@/lib/markdown";
44

55
export function AppGitHubReadme() {
66
const [readme, setReadme] = useState<string>("Loading...");
@@ -24,7 +24,7 @@ export function AppGitHubReadme() {
2424

2525
return (
2626
<div>
27-
<Markdown>{readme}</Markdown>
27+
<MarkdownToJSX content={readme} />
2828
</div>
2929
);
3030
}

src/lib/markdown.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { fromMarkdown } from "mdast-util-from-markdown";
2+
3+
export function MarkdownToJSX({ content }: { content: string }) {
4+
const tree = fromMarkdown(content);
5+
6+
function renderNode(node: any): React.ReactNode {
7+
switch (node.type) {
8+
case "paragraph":
9+
return <p className="text-red-500">{node.children.map(renderNode)}</p>;
10+
case "text":
11+
return node.value;
12+
default:
13+
return node.children?.map(renderNode);
14+
}
15+
}
16+
17+
return <div>{tree.children.map(renderNode)}</div>;
18+
}

0 commit comments

Comments
 (0)