Skip to content

Commit e5fe56b

Browse files
authored
fix markdown components rendering (#661)
1 parent 688a898 commit e5fe56b

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/components/mdx/code.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ export const Code = ({ className, ...props }) => {
1717
<Box position='relative' zIndex='0'>
1818
<CodeContainer px='0' overflow='hidden'>
1919
<SyntaxHighlighter
20-
language={props.language ? props.language : match ? match[1] : null}
20+
language={props.language || (match ? match[1] : null)}
2121
{...props}
2222
style={nord}
23-
wrapLongLines={
24-
!props.wrapLongLines ? props.wrapLongLines : match ? false : true
25-
} // enable this once https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/402 has been fixed
26-
showLineNumbers={
27-
props.showLineNumbers ? props.showLineNumbers : match ? true : false
28-
}
23+
wrapLongLines={props.wrapLongLines ? !match : props.wrapLongLines} // enable this once https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/402 has been fixed
24+
showLineNumbers={props.showLineNumbers || !!match}
2925
/>
30-
<CopyButton top='5' code={props.children} />
26+
<CopyButton top='4' right='1' code={props.children} />
3127
</CodeContainer>
3228
</Box>
3329
)

src/pages/_app.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { mapping } from '@/components/mdx'
21
import * as gtag from '@/lib/ga'
32
import { customTheme } from '@/theme'
43
import { ChakraProvider } from '@chakra-ui/react'
5-
import { MDXProvider } from '@mdx-js/react'
64
import { useRouter } from 'next/router'
75
import Script from 'next/script'
86
import { useEffect } from 'react'
@@ -43,9 +41,7 @@ function MyApp({ Component, pageProps }) {
4341
}}
4442
/>
4543

46-
<MDXProvider components={mapping}>
47-
<Component {...pageProps} />
48-
</MDXProvider>
44+
<Component {...pageProps} />
4945
</ChakraProvider>
5046
)
5147
}

src/pages/blog/[id].js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import path from 'path'
2424

2525
import { Giscus } from '@/components'
2626
import { Layout } from '@/components/layout'
27-
import { Link } from '@/components/mdx'
27+
import { Link, mapping } from '@/components/mdx'
2828
import { distanceToNow, formatDate } from '@/lib/date-formatting'
2929
import { MDXElements } from '@/lib/mdx-elements'
3030
import { getAllPostsIds, getPostData } from '@/lib/posts'
@@ -82,7 +82,10 @@ export default function Post({ source, frontmatter, postId }) {
8282
<Divider my={2} />
8383
</VStack>
8484
<br></br>
85-
<MDXRemote {...source} components={MDXElements} />
85+
<MDXRemote
86+
{...source}
87+
components={{ ...mapping, ...MDXElements }}
88+
/>
8689
</Box>
8790

8891
<Button

0 commit comments

Comments
 (0)