Skip to content

Commit a9528fb

Browse files
committed
Handle tables.
1 parent c07e5a7 commit a9528fb

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/lib/markdown.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import React from "react";
22

3+
import { AppMarkdownTable } from "@/components/libresplit/AppMarkdownTable";
34
import { fromMarkdown } from "mdast-util-from-markdown";
45
import { CodeBlock } from "react-code-block";
6+
import { gfm } from "micromark-extension-gfm";
7+
import { gfmFromMarkdown } from "mdast-util-gfm";
58

69
export function Markdown({ content }: { content: string }) {
7-
const tree = fromMarkdown(content);
10+
const tree = fromMarkdown(content, {
11+
extensions: [gfm()],
12+
mdastExtensions: [gfmFromMarkdown()],
13+
});
814

915
function renderChildren(node: any): React.ReactNode | null {
1016
if (!node.children) {
@@ -79,6 +85,19 @@ export function Markdown({ content }: { content: string }) {
7985
return <li>{renderChildren(node)}</li>;
8086
}
8187

88+
// Handles tables.
89+
case "table":
90+
return (
91+
<AppMarkdownTable
92+
node={node}
93+
renderChildren={(n) =>
94+
n?.children?.map((c: any, i: number) => (
95+
<React.Fragment key={i}>{renderNode(c)}</React.Fragment>
96+
))
97+
}
98+
/>
99+
);
100+
82101
// Handles code blocks.
83102
case "code":
84103
return (

0 commit comments

Comments
 (0)