1
1
import Link from 'next/link' ;
2
2
import React , { memo } from 'react' ;
3
- import ReactMarkdown , { type Components } from 'react-markdown ' ;
4
- import remarkGfm from 'remark-gfm' ;
5
- import { CodeBlock } from './code-block' ;
3
+ import { Streamdown , type StreamdownProps } from 'streamdown ' ;
4
+
5
+ type Components = StreamdownProps [ 'components' ] ;
6
6
7
7
const components : Partial < Components > = {
8
- // @ts -expect-error
9
- code : CodeBlock ,
10
- pre : ( { children } ) => < > { children } </ > ,
11
- ol : ( { node, children, ...props } ) => {
12
- return (
13
- < ol className = "list-decimal list-outside ml-4" { ...props } >
14
- { children }
15
- </ ol >
16
- ) ;
17
- } ,
18
- li : ( { node, children, ...props } ) => {
19
- return (
20
- < li className = "py-1" { ...props } >
21
- { children }
22
- </ li >
23
- ) ;
24
- } ,
25
- ul : ( { node, children, ...props } ) => {
26
- return (
27
- < ul className = "list-decimal list-outside ml-4" { ...props } >
28
- { children }
29
- </ ul >
30
- ) ;
31
- } ,
32
- strong : ( { node, children, ...props } ) => {
33
- return (
34
- < span className = "font-semibold" { ...props } >
35
- { children }
36
- </ span >
37
- ) ;
38
- } ,
39
8
a : ( { node, children, ...props } ) => {
40
9
return (
41
10
// @ts -expect-error
@@ -49,59 +18,11 @@ const components: Partial<Components> = {
49
18
</ Link >
50
19
) ;
51
20
} ,
52
- h1 : ( { node, children, ...props } ) => {
53
- return (
54
- < h1 className = "text-3xl font-semibold mt-6 mb-2" { ...props } >
55
- { children }
56
- </ h1 >
57
- ) ;
58
- } ,
59
- h2 : ( { node, children, ...props } ) => {
60
- return (
61
- < h2 className = "text-2xl font-semibold mt-6 mb-2" { ...props } >
62
- { children }
63
- </ h2 >
64
- ) ;
65
- } ,
66
- h3 : ( { node, children, ...props } ) => {
67
- return (
68
- < h3 className = "text-xl font-semibold mt-6 mb-2" { ...props } >
69
- { children }
70
- </ h3 >
71
- ) ;
72
- } ,
73
- h4 : ( { node, children, ...props } ) => {
74
- return (
75
- < h4 className = "text-lg font-semibold mt-6 mb-2" { ...props } >
76
- { children }
77
- </ h4 >
78
- ) ;
79
- } ,
80
- h5 : ( { node, children, ...props } ) => {
81
- return (
82
- < h5 className = "text-base font-semibold mt-6 mb-2" { ...props } >
83
- { children }
84
- </ h5 >
85
- ) ;
86
- } ,
87
- h6 : ( { node, children, ...props } ) => {
88
- return (
89
- < h6 className = "text-sm font-semibold mt-6 mb-2" { ...props } >
90
- { children }
91
- </ h6 >
92
- ) ;
93
- } ,
94
21
} ;
95
22
96
- const remarkPlugins = [ remarkGfm ] ;
97
-
98
- const NonMemoizedMarkdown = ( { children } : { children : string } ) => {
99
- return (
100
- < ReactMarkdown remarkPlugins = { remarkPlugins } components = { components } >
101
- { children }
102
- </ ReactMarkdown >
103
- ) ;
104
- } ;
23
+ const NonMemoizedMarkdown = ( { children } : { children : string } ) => (
24
+ < Streamdown components = { components } > { children } </ Streamdown >
25
+ ) ;
105
26
106
27
export const Markdown = memo (
107
28
NonMemoizedMarkdown ,
0 commit comments