Skip to content

Commit

Permalink
change default options for compileMdx, set jsx: false and `output…
Browse files Browse the repository at this point in the history
…Format: 'function-body'` by default (#869)

* change default options for `compileMdx`, set `jsx: false` and `outputFormat: 'function-body'` by default

* fix ci
  • Loading branch information
dimaMachina committed Oct 7, 2022
1 parent 02bc6fc commit f7856a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-ads-chew.md
@@ -0,0 +1,5 @@
---
'nextra': patch
---

change default options for `compileMdx`, set `jsx: false` and `outputFormat: 'function-body'` by default
15 changes: 10 additions & 5 deletions packages/nextra/__test__/compile.test.ts
Expand Up @@ -16,30 +16,35 @@ function loadFixture(name: Name) {
return fs.readFile(filePath, 'utf8')
}

const mdxOptions = {
jsx: true,
outputFormat: 'program' as const
}

describe('process heading', () => {
it('code-h1', async () => {
const data = await loadFixture('code-h1.mdx')
const result = await compileMdx(data)
const result = await compileMdx(data, { mdxOptions })
expect(result).toMatchSnapshot()
})
it('code-with-text-h1', async () => {
const data = await loadFixture('code-with-text-h1.mdx')
const result = await compileMdx(data)
const result = await compileMdx(data, { mdxOptions })
expect(result).toMatchSnapshot()
})
it('static-h1', async () => {
const data = await loadFixture('static-h1.mdx')
const result = await compileMdx(data)
const result = await compileMdx(data, { mdxOptions })
expect(result).toMatchSnapshot()
})
it('dynamic-h1', async () => {
const data = await loadFixture('dynamic-h1.mdx')
const result = await compileMdx(data)
const result = await compileMdx(data, { mdxOptions })
expect(result).toMatchSnapshot()
})
it('no-h1', async () => {
const data = await loadFixture('no-h1.mdx')
const result = await compileMdx(data)
const result = await compileMdx(data, { mdxOptions })
expect(result).toMatchSnapshot()
})
})
4 changes: 2 additions & 2 deletions packages/nextra/src/compile.ts
Expand Up @@ -60,8 +60,8 @@ export async function compileMdx(
const mdxOptions = loaderOptions.mdxOptions || {}

const compiler = createCompiler({
jsx: mdxOptions.jsx ?? true,
outputFormat: mdxOptions.outputFormat,
jsx: mdxOptions.jsx || false,
outputFormat: mdxOptions.outputFormat || 'function-body',
providerImportSource: '@mdx-js/react',
remarkPlugins: [
...(mdxOptions.remarkPlugins || []),
Expand Down
6 changes: 5 additions & 1 deletion packages/nextra/src/loader.ts
Expand Up @@ -119,7 +119,11 @@ async function loader(
await compileMdx(
content,
{
mdxOptions,
mdxOptions: {
...mdxOptions,
jsx: true,
outputFormat: 'program',
},
unstable_readingTime,
unstable_defaultShowCopyCode,
unstable_staticImage,
Expand Down

0 comments on commit f7856a1

Please sign in to comment.