1- import React , { useEffect , useRef , useState } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import { useParams } from 'react-router-dom' ;
33import ReactMarkdown from 'react-markdown' ;
44import remarkGfm from 'remark-gfm' ;
@@ -7,27 +7,29 @@ import { a11yDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
77import { Spin , Alert } from 'antd' ;
88import Layout from '../../../components/Layout/Layout' ;
99
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+
1026const DocDetail = ( ) => {
1127 const { slug } = useParams ( ) ;
1228 const [ content , setContent ] = useState ( '' ) ;
1329 const [ loading , setLoading ] = useState ( true ) ;
1430 const [ error , setError ] = useState ( null ) ;
1531 const [ activeSection , setActiveSection ] = useState ( null ) ;
1632 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- } , [ ] ) ;
3133
3234 useEffect ( ( ) => {
3335 const fetchContent = async ( ) => {
@@ -55,6 +57,7 @@ const DocDetail = () => {
5557 while ( ( match = regex . exec ( markdown ) ) !== null ) {
5658 const level = match [ 0 ] . split ( ' ' ) [ 0 ] . length ;
5759 const title = match [ 1 ] ;
60+ if ( level > 3 ) continue ;
5861 headings . push ( { level, title } ) ;
5962 }
6063 setHeadings ( headings ) ;
@@ -87,7 +90,7 @@ const DocDetail = () => {
8790 { slug . replace ( / _ / g, ' ' ) }
8891 </ h3 >
8992 < 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" >
9194 < h2 className = "text-xl font-bold mb-2" > Table of Contents</ h2 >
9295 < ul className = 'grid gap-2' >
9396 { headings . map ( ( heading , index ) => (
@@ -132,7 +135,19 @@ const DocDetail = () => {
132135 h3 ( { node, children } ) {
133136 return < h3 className = 'text-xl font-normal mt-10 mb-3' id = { children . toLowerCase ( ) . replace ( / \s + / g, '-' ) } > 🌿 { children } </ h3 > ;
134137 } ,
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+ }
136151 } }
137152 >
138153 { content }
0 commit comments