File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed
Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ import remarkPrism from 'remark-prism'
44import rehypeSlug from 'rehype-slug'
55import rehypeAutolinkHeadings from 'rehype-autolink-headings'
66import { docQueries } from '../../../queries'
7- import { remarkFixLinks } from '../../../util/remark-fix-links'
7+ import {
8+ remarkFixLinks ,
9+ remarkResponsiveTables
10+ } from '../../../util/remark-plugins'
811import DocsPage from '../[slug]'
912
1013export const getStaticPaths : GetStaticPaths = async ( ) => {
@@ -29,7 +32,7 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
2932 // READMEs should not contain live code blocks
3033 const mdx = await serialize ( content , {
3134 mdxOptions : {
32- remarkPlugins : [ remarkPrism , remarkFixLinks ] ,
35+ remarkPlugins : [ remarkPrism , remarkFixLinks , remarkResponsiveTables ] ,
3336
3437 // rehypeSlug must come first
3538 rehypePlugins : [ rehypeSlug , rehypeAutolinkHeadings ]
Original file line number Diff line number Diff line change @@ -12,7 +12,10 @@ import rehypeSlug from 'rehype-slug'
1212import rehypeAutolinkHeadings from 'rehype-autolink-headings'
1313import { DocWrapper , ResponsiveTable , Title } from '../../components'
1414import { docQueries } from '../../queries'
15- import { remarkFixLinks } from '../../util/remark-fix-links'
15+ import {
16+ remarkFixLinks ,
17+ remarkResponsiveTables
18+ } from '../../util/remark-plugins'
1619import { mediaQueries , styleConstants } from '../../util'
1720import {
1821 remarkLiveEditor ,
@@ -41,7 +44,12 @@ export async function getStaticProps({ params }: GetStaticPropsContext) {
4144 const mdx = await serialize ( content , {
4245 mdxOptions : {
4346 // remarkLiveEditor must come before remarkPrism
44- remarkPlugins : [ remarkLiveEditor , remarkPrism , remarkFixLinks ] ,
47+ remarkPlugins : [
48+ remarkLiveEditor ,
49+ remarkPrism ,
50+ remarkFixLinks ,
51+ remarkResponsiveTables
52+ ] ,
4553
4654 // rehypeSlug must come first
4755 rehypePlugins : [ rehypeSlug , rehypeAutolinkHeadings ]
@@ -123,7 +131,7 @@ export default function DocsPage({
123131 < MDXRemote
124132 { ...mdx }
125133 components = { {
126- table : ResponsiveTable ,
134+ ResponsiveTable,
127135 EmotionLiveEditor
128136 } }
129137 />
Original file line number Diff line number Diff line change 11import { visit } from 'unist-util-visit'
22
33export function remarkFixLinks ( ) {
4- return ( markdownAST : any ) =>
4+ return ( markdownAST : any ) => {
55 visit ( markdownAST , 'link' , ( node : { url : string } ) => {
66 node . url = node . url . replace ( / ^ h t t p s ? : \/ \/ e m o t i o n .s h / , '' )
77
@@ -13,4 +13,15 @@ export function remarkFixLinks() {
1313 . replace ( / ^ \/ p a c k a g e s \/ / , '/docs/@emotion/' )
1414 }
1515 } )
16+ }
17+ }
18+
19+ export function remarkResponsiveTables ( ) {
20+ return ( markdownAST : any ) => {
21+ visit ( markdownAST , 'mdxJsxFlowElement' , ( node : any ) => {
22+ if ( node . name === 'table' ) {
23+ node . name = 'ResponsiveTable'
24+ }
25+ } )
26+ }
1627}
You can’t perform that action at this time.
0 commit comments