@@ -15,13 +15,13 @@ const MarkdownCode = CodeLayout.Preview;
1515const Code = CodeLayout . Code ;
1616const Toolbar = CodeLayout . Toolbar ;
1717
18- const Wrapper = styled . div < { isShowExample ?: boolean } > `
18+ const Wrapper = styled . div < { $ isShowExample ?: boolean } > `
1919 flex: 1;
2020 padding-right: 0.51rem;
2121 padding-left: 0.51rem;
2222 overflow: hidden;
2323 z-index: 1;
24- padding-top: ${ ( { isShowExample } ) => ( isShowExample ? '0' : '0' ) } ;
24+ padding-top: ${ ( { $ isShowExample } ) => ( $ isShowExample ? '0' : '0' ) } ;
2525 margin: 0 auto;
2626 width: 100%;
2727 ${ mediaStyle }
@@ -95,52 +95,34 @@ export const Preview: FC<PropsWithChildren<PreviewProps>> = (props) => {
9595 </ PageArrow >
9696 </ NavMenu >
9797 ) }
98- < Wrapper isShowExample = { props . disableNav } >
98+ < Wrapper $ isShowExample= { props . disableNav } >
9999 { loading && < div > Loading...</ div > }
100100 { mdData && ! loading && (
101101 < Markdown
102102 source = { mdData . source }
103103 rehypeRewrite = { ( node : Root | RootContent , index : number , parent : Root | Element ) => {
104104 if ( node . type === 'element' && parent && parent . type === 'root' ) {
105- const menu = parent . children [ 1 ] as Element | undefined ;
106- let childLength = [ ...parent . children ] . filter ( ( item ) => item . type !== 'raw' ) . length ;
107- const lastChild = parent . children [ parent . children . length - 1 ] ;
108- if ( lastChild ?. type === 'raw' ) {
109- childLength = parent . children . length - 2 ;
110- }
111- if (
112- ( index + 1 === childLength || index - 1 === childLength || index === childLength ) &&
113- menu ?. properties ?. class !== 'menu-toc'
114- ) {
115- const child = [ ...parent . children ] . map ( ( item ) => {
116- if ( item . type === 'element' && item . tagName === 'pre' ) {
117- const meta = item . children [ 0 ] ?. data ?. meta as string ;
118- if ( isMeta ( meta ) ) {
119- item . tagName = 'div' ;
120- item . properties = {
121- ...item . properties ,
122- 'data-md' : meta ,
123- 'data-meta' : 'preview' ,
124- } ;
125- return { ...item } ;
126- }
105+ [ ...parent . children ] . map ( ( item ) => {
106+ if ( item . type === 'element' && item . tagName === 'pre' ) {
107+ const meta = ( item . children [ 0 ] ?. data as any ) ?. meta as string ;
108+ if ( isMeta ( meta ) ) {
109+ item . tagName = 'div' ;
110+ item . properties = {
111+ ...item . properties ,
112+ 'data-md' : meta ,
113+ 'data-meta' : 'preview' ,
114+ } ;
115+ return { ...item } ;
127116 }
128- return item ;
129- } ) ;
130- parent . children = [
131- {
132- type : 'element' ,
133- tagName : 'div' ,
134- children : child as Element [ ] ,
135- } ,
136- ] ;
137- }
117+ }
118+ return item ;
119+ } ) ;
138120 }
139121 } }
140122 components = { {
141123 div : ( { node, ...props } ) => {
142124 const { 'data-meta' : meta , 'data-md' : metaData , ...rest } = props as any ;
143- const line = node . position ?. start . line ;
125+ const line = node ? .position ?. start . line ;
144126 const metaId = getMetaId ( metaData ) || String ( line ) ;
145127 const Child = mdData . components [ metaId ] ;
146128 if ( meta !== 'preview' || ! metaId || typeof Child !== 'function' ) return < div { ...props } /> ;
0 commit comments