1
- import React , { useEffect , useRef , useState } from 'react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
2
import { useParams } from 'react-router-dom' ;
3
3
import ReactMarkdown from 'react-markdown' ;
4
4
import remarkGfm from 'remark-gfm' ;
@@ -7,27 +7,29 @@ import { a11yDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
7
7
import { Spin , Alert } from 'antd' ;
8
8
import Layout from '../../../components/Layout/Layout' ;
9
9
10
+ const Table = ( { children } ) => {
11
+ return < table className = "min-w-full mt-4 border border-gray-300" > { children } </ table > ;
12
+ } ;
13
+
14
+ const TableRow = ( { children } ) => {
15
+ return < tr className = "border-b border-gray-300" > { children } </ tr > ;
16
+ } ;
17
+
18
+ const TableCell = ( { children } ) => {
19
+ return < td className = "px-4 py-2" > { children } </ td > ;
20
+ } ;
21
+
22
+ const TableHeader = ( { children } ) => {
23
+ return < th className = "px-4 py-2 bg-gray-100 font-bold" > { children } </ th > ;
24
+ } ;
25
+
10
26
const DocDetail = ( ) => {
11
27
const { slug } = useParams ( ) ;
12
28
const [ content , setContent ] = useState ( '' ) ;
13
29
const [ loading , setLoading ] = useState ( true ) ;
14
30
const [ error , setError ] = useState ( null ) ;
15
31
const [ activeSection , setActiveSection ] = useState ( null ) ;
16
32
const [ headings , setHeadings ] = useState ( [ ] ) ;
17
- const tableRef = useRef ( null ) ;
18
-
19
- useEffect ( ( ) => {
20
- const handleScroll = ( ) => {
21
- if ( tableRef . current ) {
22
- const rect = tableRef . current . getBoundingClientRect ( ) ;
23
- const isTableVisible = rect . top <= 0 && rect . bottom >= 100 ;
24
- setIsSticky ( isTableVisible ) ;
25
- }
26
- } ;
27
-
28
- window . addEventListener ( 'scroll' , handleScroll ) ;
29
- return ( ) => window . removeEventListener ( 'scroll' , handleScroll ) ;
30
- } , [ ] ) ;
31
33
32
34
useEffect ( ( ) => {
33
35
const fetchContent = async ( ) => {
@@ -55,6 +57,7 @@ const DocDetail = () => {
55
57
while ( ( match = regex . exec ( markdown ) ) !== null ) {
56
58
const level = match [ 0 ] . split ( ' ' ) [ 0 ] . length ;
57
59
const title = match [ 1 ] ;
60
+ if ( level > 3 ) continue ;
58
61
headings . push ( { level, title } ) ;
59
62
}
60
63
setHeadings ( headings ) ;
@@ -87,7 +90,7 @@ const DocDetail = () => {
87
90
{ slug . replace ( / _ / g, ' ' ) }
88
91
</ h3 >
89
92
< div className = "flex" >
90
- < aside ref = { tableRef } className = "sticky top-20 w-1/4 p-4 h-0" >
93
+ < aside className = "sticky top-20 w-1/4 p-4 h-0" >
91
94
< h2 className = "text-xl font-bold mb-2" > Table of Contents</ h2 >
92
95
< ul className = 'grid gap-2' >
93
96
{ headings . map ( ( heading , index ) => (
@@ -132,7 +135,19 @@ const DocDetail = () => {
132
135
h3 ( { node, children } ) {
133
136
return < h3 className = 'text-xl font-normal mt-10 mb-3' id = { children . toLowerCase ( ) . replace ( / \s + / g, '-' ) } > 🌿 { children } </ h3 > ;
134
137
} ,
135
- // Handle other heading levels if needed
138
+ blockquote ( { node, children } ) {
139
+ return < span className = 'bg-gray-100 p-4 pl-0 text-sm my-4 block text-gray' > { children } </ span > ;
140
+ } ,
141
+ table : Table ,
142
+ tr : TableRow ,
143
+ td : TableCell ,
144
+ th : TableHeader ,
145
+ li ( { node, children } ) {
146
+ return < li className = 'list-disc ml-4' > { children } </ li > ;
147
+ } ,
148
+ ul ( { node, children } ) {
149
+ return < ul className = 'list-disc ml-4 mb-2' > { children } </ ul > ;
150
+ }
136
151
} }
137
152
>
138
153
{ content }
0 commit comments