Skip to content

Commit 280290b

Browse files
committed
remark-responsive-tables
1 parent 14f73a8 commit 280290b

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

site/pages/docs/@emotion/[packageName].tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import remarkPrism from 'remark-prism'
44
import rehypeSlug from 'rehype-slug'
55
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
66
import { docQueries } from '../../../queries'
7-
import { remarkFixLinks } from '../../../util/remark-fix-links'
7+
import {
8+
remarkFixLinks,
9+
remarkResponsiveTables
10+
} from '../../../util/remark-plugins'
811
import DocsPage from '../[slug]'
912

1013
export 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]

site/pages/docs/[slug].tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import rehypeSlug from 'rehype-slug'
1212
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
1313
import { DocWrapper, ResponsiveTable, Title } from '../../components'
1414
import { docQueries } from '../../queries'
15-
import { remarkFixLinks } from '../../util/remark-fix-links'
15+
import {
16+
remarkFixLinks,
17+
remarkResponsiveTables
18+
} from '../../util/remark-plugins'
1619
import { mediaQueries, styleConstants } from '../../util'
1720
import {
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
/>

site/util/remark-fix-links.ts renamed to site/util/remark-plugins.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { visit } from 'unist-util-visit'
22

33
export function remarkFixLinks() {
4-
return (markdownAST: any) =>
4+
return (markdownAST: any) => {
55
visit(markdownAST, 'link', (node: { url: string }) => {
66
node.url = node.url.replace(/^https?:\/\/emotion.sh/, '')
77

@@ -13,4 +13,15 @@ export function remarkFixLinks() {
1313
.replace(/^\/packages\//, '/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
}

0 commit comments

Comments
 (0)