Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to MDX v2 #8288

Merged
merged 176 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 129 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
0833b06
upgrade mdx
slorber Nov 3, 2022
2c98f91
fix TOC?
slorber Nov 3, 2022
84544bd
progress on mdx 2 upgrade, use dynamic imports for ESM packages
slorber Nov 3, 2022
64f5102
make subset of the site build with MDX 2
slorber Nov 4, 2022
5b19968
netlify deploy quickfix
slorber Nov 4, 2022
1bf2e82
add _ to canary for now
slorber Nov 4, 2022
83064b2
Add ability to escape heading anchor link syntax
slorber Nov 4, 2022
0f95038
almost working unwrapMdxCodeBlocks
slorber Nov 4, 2022
a38aff7
add proper unwrapMdxCodeBlocks fn
slorber Nov 4, 2022
147985b
re-enable blog
slorber Nov 4, 2022
2ba0043
remove <!--truncate--> before MDX compilation
slorber Nov 4, 2022
55ef6b9
strip html comments
slorber Nov 4, 2022
f6e164a
try to render docs
slorber Nov 9, 2022
c22688d
render full site?
slorber Nov 9, 2022
fa6c9f5
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 10, 2022
20ea1b1
code block quickfix
slorber Nov 10, 2022
2949aa5
add codeCompatPlugin
slorber Nov 12, 2022
fccc228
copy handling of md images from https://github.com/pomber/docusaurus-…
slorber Nov 12, 2022
9f1d8d5
update remark transformLinks inspired by https://github.com/pomber/do…
slorber Nov 12, 2022
79dca20
fix transformImage merge
slorber Nov 12, 2022
a8ca394
try to implement admonitions with remark-directives
slorber Nov 12, 2022
a9c1e2a
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 17, 2022
37806c3
test admonitions
slorber Nov 17, 2022
d875f63
import ContainerDirective type
slorber Nov 18, 2022
08ed0cd
add todo
slorber Nov 18, 2022
7b1779f
make admonition directive label POC work with previous workaround
slorber Nov 18, 2022
8a17cad
Merge branch 'main' into slorber/mdx-2.0
slorber Nov 24, 2022
25feea3
cleanup admonition implementation
slorber Nov 24, 2022
3c4a00e
add ability to transform legacy admonition titles
slorber Nov 24, 2022
5f00e10
restore changelog plugin + minor mdx fixes
slorber Nov 24, 2022
311095b
fix admonitionTitleToDirectiveLabel edge case
slorber Nov 25, 2022
a7d412c
fix code block title typo
slorber Nov 25, 2022
db5893c
almost working npm2yarn
slorber Nov 25, 2022
d378146
better mdx Jest vendoring setup
slorber Nov 30, 2022
bba54bd
update safe snapshots
slorber Nov 30, 2022
c14bf34
make npm2yarn work + unit tests + update snapshots
slorber Dec 1, 2022
aedb12f
some PR cleanup
slorber Dec 1, 2022
5cff7df
fix math/katex
slorber Dec 1, 2022
b404d0c
useless diff line break
slorber Dec 1, 2022
47ec626
fix remark configTabs plugin
slorber Dec 1, 2022
6a67822
remove useless escaping line
slorber Dec 1, 2022
174621e
Fix remark GFM import + APITable
slorber Dec 1, 2022
0bb3d84
apply codeCompatPlugin last
slorber Dec 1, 2022
bf358c9
add dogfood for remark-emoji
slorber Dec 1, 2022
bcd7a1b
fix weird ts
slorber Dec 1, 2022
4c0400a
unsuccessful attempt to use mdxJsxFlowElement for admonition
slorber Dec 2, 2022
1f20c7b
extract md preprocessor
slorber Dec 2, 2022
44c89bb
fix admonition implementation + unit tests
slorber Dec 2, 2022
e9c406e
move containerDirective comment
slorber Dec 2, 2022
73efc94
vendor [email protected]
slorber Dec 2, 2022
abf8e9c
fix transformImage
slorber Dec 2, 2022
02f48b1
fix transformLinks + tests
slorber Dec 2, 2022
0bf628c
vendor [email protected]
slorber Dec 2, 2022
6ccc437
useless import
slorber Dec 2, 2022
1d4d103
vendor [email protected]
slorber Dec 2, 2022
80cbd0f
fix TOC tests
slorber Dec 2, 2022
f8ad8ac
fix remark headings tests
slorber Dec 2, 2022
557d3d0
delete older unwrapMdxCodeBlocks impl
slorber Dec 2, 2022
033e4d8
fix mermaid tests
slorber Dec 2, 2022
48f76f8
comment
slorber Dec 2, 2022
8b9c7b0
vendor @mdx-js/mdx
slorber Dec 2, 2022
99758d3
fix footnoteIDFixer tests
slorber Dec 2, 2022
7758280
useless comment
slorber Dec 2, 2022
a361694
TS errors workaround?
slorber Dec 2, 2022
9b46551
re-add all site versions
slorber Dec 2, 2022
4513c0f
fix docs
slorber Dec 4, 2022
b92c7a2
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 7, 2022
99ef409
ensure markdown config and throw error if missing
slorber Dec 7, 2022
4a0007f
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 9, 2022
d4642ad
add admonitions in tabs test case
slorber Dec 15, 2022
fbd8fa3
add ability to provide custom mdx format with frontMatter
slorber Dec 15, 2022
ce2f472
changelog: revert mdx2 changes + use format: 'md'
slorber Dec 15, 2022
26e6d9d
changelog: use format: 'md'
slorber Dec 15, 2022
ce487b7
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 15, 2022
d29c50a
fix extractMDXAdmonitionTitle bug
slorber Dec 15, 2022
274c3b8
fix details/summary
slorber Dec 15, 2022
e22567d
Merge branch 'main' into slorber/mdx-2.0
slorber Dec 16, 2022
59448c1
add deps
slorber Dec 16, 2022
8c2b93d
Fix <Head> support
slorber Dec 16, 2022
599ecd4
update truncate marker regexp
slorber Dec 21, 2022
0b92958
rebase
slorber Jan 5, 2023
e6d06cc
fix merge issue
slorber Jan 5, 2023
2703af7
fix <Tabs> after refactor
slorber Jan 5, 2023
2b1a1cf
rename markdown test page
slorber Jan 5, 2023
62cd8b1
add markdown .md test page
slorber Jan 5, 2023
2163ba3
broken link
slorber Jan 5, 2023
05bd2df
format: "detect"
slorber Jan 6, 2023
05279ec
format: "detect"
slorber Jan 6, 2023
cbfc8f1
Merge branch 'main' into slorber/mdx-2.0
slorber Jan 6, 2023
d68ca28
remove useless duplicate jest/vendor ignores
slorber Jan 6, 2023
1457a23
yarnlock cleanup
slorber Jan 6, 2023
68c75d3
remove MDXComponents/Head from swizzle config
slorber Jan 6, 2023
3bc5cbd
remove useless MDX pragma/runtime/deps
slorber Jan 6, 2023
5ca05f3
improve "yarn clear" command: cleanup create-docusaurus tests
slorber Jan 6, 2023
1c69210
restore needed dependency :D
slorber Jan 6, 2023
a132d89
Merge branch 'main' into slorber/mdx-2.0
slorber Jan 6, 2023
77d7356
docs(website): use MDX comments instead of HTML comments (#8516)
slorber Jan 6, 2023
86e39a1
revert unwanted blog docs truncate marker change
slorber Jan 6, 2023
cad8f74
Add MDX comment truncation docs
slorber Jan 6, 2023
65eee40
Add MDX comment truncation docs
slorber Jan 6, 2023
6e46b62
add remark-comment to support html comments like MDX 1
slorber Jan 6, 2023
d0cc3c8
update blog truncateMarker regexp doc
slorber Jan 6, 2023
9295366
better comment
slorber Jan 6, 2023
e75e602
restore cspell comment
slorber Jan 6, 2023
31cf322
remove useless mdx <Code> inline render logic
slorber Jan 6, 2023
2d3ff9b
restore code inline logic for inline code blocks
slorber Jan 6, 2023
44882e4
Simplify MDXPre, unneeded remove originalType
slorber Jan 6, 2023
32b0f1a
mdx2 pr should build all versions
slorber Jan 20, 2023
fa3f418
merge
slorber Jan 20, 2023
6f6627a
fix blog api table
slorber Jan 20, 2023
9c30f0f
make mdx2 deploy preview use same lastVersion as prod
slorber Jan 20, 2023
088ed75
Merge branch 'main' into slorber/mdx-2.0
slorber Feb 3, 2023
d0ab202
Fix 2.3.1 doc for MDX 2
slorber Feb 3, 2023
1e1ed03
merge from main
slorber Feb 24, 2023
491f3ef
merge lockfile
slorber Feb 24, 2023
6094a99
merge npm2yarn plugin changes, adapted for MDX 2
slorber Feb 24, 2023
d310028
prettier
slorber Feb 24, 2023
e398622
remove useless admonition paragraph
slorber Feb 24, 2023
fbd5a85
fix live codeblock metastring to live=true prop
slorber Feb 24, 2023
4f302a0
Merge branch 'main' into slorber/mdx-2.0
slorber Mar 3, 2023
61ea354
fix blockquote to produce identical mdx markup
slorber Mar 3, 2023
86fda50
fix precaching blockquote heading to produce identical mdx markup
slorber Mar 3, 2023
c9405f8
fix admonition to produce identical mdx markup
slorber Mar 3, 2023
0b5db1b
make files docs mdx to produce identical jsx markup
slorber Mar 3, 2023
00bd106
make code block docs mdx to produce identical jsx markup
slorber Mar 3, 2023
2d24c16
make react docs mdx to produce identical jsx markup
slorber Mar 3, 2023
6b71a8b
make autogenerated docs mdx to produce identical jsx markup
slorber Mar 3, 2023
fe5c77f
make versioning docs mdx to produce identical jsx markup
slorber Mar 3, 2023
f104c6d
fix: correct MDXPlugin type (#8738)
armano2 Mar 6, 2023
2f6ff73
Fix unified issue in docusaurus-migrate :/
slorber Mar 9, 2023
0027998
merge main
slorber Mar 10, 2023
43bdab9
Fix TS issues after merge
slorber Mar 10, 2023
7efc696
remove useless TS expect error for npm2yarn remark plugin
slorber Mar 10, 2023
7ef4c99
PWA docs: fix Argos diff detected on TOC
slorber Mar 10, 2023
ac4b06e
Merge branch 'main' into slorber/mdx-2.0
slorber Mar 17, 2023
8b089b4
links: MDX flow => text element
slorber Mar 17, 2023
925ef67
improve transformLink types
slorber Mar 17, 2023
4808e73
add transformLinks/images in paragraph fixtures
slorber Mar 17, 2023
eaac2e3
transformImages => use mdxJsxTextElement + improve typing
slorber Mar 17, 2023
55b3509
fix doc for custom heading id syntax due to mdx file pre-processing
slorber Mar 17, 2023
dc86c92
improve npm2yarn typing
slorber Mar 17, 2023
2aa97d9
minor comment change
slorber Mar 17, 2023
a562d29
re-enable eslint rule + fix errors
slorber Mar 17, 2023
2670cc1
mdx-code-block should only unwrap on the 1st level
slorber Mar 17, 2023
ab6d3dc
Admonition api: remove support for using a custom tag option
slorber Mar 17, 2023
66317de
admonitions: change extendDefaults default value
slorber Mar 17, 2023
325826b
admonitions: remove docs for tag option in current version
slorber Mar 17, 2023
41197a6
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 7, 2023
cd50475
fix introduction page
slorber Apr 7, 2023
2641fcd
backport 2.4 docs mdx changes
slorber Apr 7, 2023
a8131ec
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 13, 2023
22449f2
Add siteConfig.markdown.mdx1Compat config
slorber Apr 13, 2023
5f0a507
add proper markdown.mdx1Compat + markdown.preprocessor support + dogf…
slorber Apr 14, 2023
6470c2c
fix snapshot
slorber Apr 14, 2023
d57382c
Better MDX compilation error messages
slorber Apr 14, 2023
37cb892
restore 4-backticks mdx-code-block (used on our own website)
slorber Apr 14, 2023
c30e92f
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 14, 2023
a3226f5
minor preprocessor bug due to markdown links having spaces
slorber Apr 14, 2023
bb94f8f
fix diff for /tests/docs/tests/admonitions
slorber Apr 14, 2023
130be08
Add shitty non-breaking space hack to document mdx-code-block: the do…
slorber Apr 14, 2023
47f2cad
fix admonition extra paragraph
slorber Apr 14, 2023
d6f51f1
react page diff fix
slorber Apr 14, 2023
cfdadae
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 20, 2023
03c5393
fix admonitions docs diff
slorber Apr 20, 2023
44fe1d6
Mention mdx v1 code block test page is legacy
slorber Apr 20, 2023
1da05da
Add TODO comment
slorber Apr 20, 2023
c98a148
Merge branch 'main' into slorber/mdx-2.0
slorber Apr 21, 2023
8f205be
report config changes for mdx v2
slorber Apr 21, 2023
3299da1
Add missing unified deps
slorber Apr 21, 2023
8129a53
Relax typing for Unified Plugin type due to TS making it very hard to…
slorber Apr 21, 2023
94408de
update docs for math equations
slorber Apr 21, 2023
55e42c3
update docs for admonitions
slorber Apr 21, 2023
2e033b0
Fix mdx loader caching issues
slorber Apr 21, 2023
a983945
update todo message
slorber Apr 21, 2023
a8754c5
Use nbsp hack to keep former admonition title doc retrocompatible
slorber Apr 21, 2023
5ab8e86
Revert website config changes before merge
slorber Apr 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ module.exports = {
// We don't provide any escape hatches for this rule. Rest siblings and
// function placeholder params are always ignored, and any other unused
// locals must be justified with a disable comment.
'@typescript-eslint/no-unused-vars': [ERROR, {ignoreRestSiblings: true}],
// TODO revert to error + add varsIgnorePattern _ prefix
'@typescript-eslint/no-unused-vars': [WARNING, {ignoreRestSiblings: true}],
'@typescript-eslint/prefer-optional-chain': ERROR,
'@docusaurus/no-html-links': ERROR,
'@docusaurus/prefer-docusaurus-heading': ERROR,
Expand Down
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ packages/docusaurus-*/lib/*
packages/create-docusaurus/lib/*
packages/create-docusaurus/templates/
website/static/katex/katex.min.css

jest/vendor
13 changes: 13 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ export default {
'@docusaurus/plugin-content-docs/src/client/index.ts',

'@testing-utils/(.*)': '<rootDir>/jest/utils/$1.ts',

// MDX packages are ESM-only and it is a pain to use in Jest
// So we use them in Jest tests as CJS versions
// see https://mdxjs.com/docs/troubleshooting-mdx/#problems-integrating-mdx
'^@mdx-js/mdx$': '<rootDir>/jest/vendor/@[email protected]',
'^remark$': '<rootDir>/jest/vendor/[email protected]',
'^remark-mdx$': '<rootDir>/jest/vendor/[email protected]',
'^remark-directive$': '<rootDir>/jest/vendor/[email protected]',
'^remark-gfm$': '<rootDir>/jest/vendor/[email protected]',
'^estree-util-value-to-estree$':
'<rootDir>/jest/vendor/[email protected]',
'^mdast-util-to-string$':
'<rootDir>/jest/vendor/[email protected]',
slorber marked this conversation as resolved.
Show resolved Hide resolved
},
snapshotSerializers: [
'<rootDir>/jest/snapshotPathNormalizer.ts',
Expand Down
7 changes: 0 additions & 7 deletions jest/deps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ declare module 'to-vfile' {
export function read(path: string, encoding?: string): Promise<VFile>;
}

declare module 'remark-mdx' {
import type {Plugin} from 'unified';

const mdx: Plugin;
export = mdx;
}

Comment on lines -16 to -22
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably more types to remove in this file?

declare module 'remark-rehype';

declare module 'rehype-stringify';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@
"test": "jest",
"test:build:website": "./admin/scripts/test-release.sh",
"watch": "yarn lerna run --parallel watch",
"clear": "(yarn workspace website clear || echo 'Failure while running docusaurus clear') && yarn lerna exec --ignore docusaurus yarn rimraf lib",
"clear": "(yarn workspace website clear || echo 'Failure while running docusaurus clear') && yarn rimraf test-website && yarn rimraf test-website-in-workspace && yarn lerna exec --ignore docusaurus yarn rimraf lib",
"test:baseUrl": "yarn build:website:baseUrl && yarn serve:website:baseUrl",
"lock:update": "npx --yes yarn-deduplicate"
},
"dependencies": {
"unified": "^9.2.2"
"unified": "^10.1.2"
},
"devDependencies": {
"@crowdin/cli": "^3.9.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
slorber marked this conversation as resolved.
Show resolved Hide resolved
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^1.6.22",
"@mdx-js/react": "^2.1.5",
"clsx": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
Expand Down
17 changes: 12 additions & 5 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@
"@babel/traverse": "^7.20.12",
"@docusaurus/logger": "^3.0.0-alpha.0",
"@docusaurus/utils": "^3.0.0-alpha.0",
"@mdx-js/mdx": "^1.6.22",
"@docusaurus/utils-validation": "^3.0.0-alpha.0",
"@mdx-js/mdx": "^2.1.5",
"escape-html": "^1.0.3",
"estree-util-value-to-estree": "^2.1.0",
"file-loader": "^6.2.0",
"fs-extra": "^11.1.0",
"hastscript": "^7.1.0",
"image-size": "^1.0.2",
"mdast-util-to-string": "^2.0.0",
"mdast-util-to-string": "^3.0.0",
"mdast-util-mdx": "^2.0.0",
"remark-comment": "^1.0.0",
"remark-gfm": "^3.0.1",
"remark-directive": "^2.0.1",
"remark-emoji": "^2.2.0",
"stringify-object": "^3.3.0",
"tslib": "^2.4.1",
"unified": "^9.2.2",
"unified": "^10.1.2",
"unist-util-visit": "^2.0.3",
"url-loader": "^4.1.1",
"webpack": "^5.75.0"
Expand All @@ -43,8 +50,8 @@
"@types/stringify-object": "^3.3.1",
"@types/unist": "^2.0.6",
"rehype-stringify": "^8.0.0",
"remark": "^12.0.1",
"remark-mdx": "^1.6.21",
"remark": "^14.0.2",
"remark-mdx": "^2.1.5",
"remark-rehype": "^8.1.0",
"to-vfile": "^6.1.0",
"unist-builder": "^2.0.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import escapeStringRegexp from 'escape-string-regexp';
import {
validateMDXFrontMatter,
DefaultMDXFrontMatter,
type MDXFrontMatter,
} from '../frontMatter';

function testField(params: {
prefix: string;
validFrontMatters: MDXFrontMatter[];
convertibleFrontMatter?: [
ConvertibleFrontMatter: {[key: string]: unknown},
ConvertedFrontMatter: MDXFrontMatter,
][];
invalidFrontMatters?: [
InvalidFrontMatter: {[key: string]: unknown},
ErrorMessage: string,
][];
}) {
// eslint-disable-next-line jest/require-top-level-describe
test(`[${params.prefix}] accept valid values`, () => {
params.validFrontMatters.forEach((frontMatter) => {
expect(validateMDXFrontMatter(frontMatter)).toEqual(frontMatter);
});
});

// eslint-disable-next-line jest/require-top-level-describe
test(`[${params.prefix}] convert valid values`, () => {
params.convertibleFrontMatter?.forEach(
([convertibleFrontMatter, convertedFrontMatter]) => {
expect(validateMDXFrontMatter(convertibleFrontMatter)).toEqual(
convertedFrontMatter,
);
},
);
});

// eslint-disable-next-line jest/require-top-level-describe
test(`[${params.prefix}] throw error for values`, () => {
params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
try {
validateMDXFrontMatter(frontMatter);
throw new Error(
`MDX front matter is expected to be rejected, but was accepted successfully:\n ${JSON.stringify(
frontMatter,
null,
2,
)}`,
);
} catch (err) {
// eslint-disable-next-line jest/no-conditional-expect
expect((err as Error).message).toMatch(
new RegExp(escapeStringRegexp(message)),
);
}
});
});
}

describe('MDX front matter schema', () => {
it('accepts empty object', () => {
const frontMatter: Partial<MDXFrontMatter> = {};
expect(validateMDXFrontMatter(frontMatter)).toEqual(DefaultMDXFrontMatter);
});

it('accepts undefined object', () => {
expect(validateMDXFrontMatter(undefined)).toEqual(DefaultMDXFrontMatter);
});

it('rejects unknown field', () => {
const frontMatter = {abc: '1'};
expect(() =>
validateMDXFrontMatter(frontMatter),
).toThrowErrorMatchingInlineSnapshot(`""abc" is not allowed"`);
});
});

describe('validateDocFrontMatter format', () => {
testField({
prefix: 'format',
validFrontMatters: [{format: 'md'}, {format: 'mdx'}],
invalidFrontMatters: [
[{format: 'xdm'}, '"format" must be one of [md, mdx, detect]'],
],
});
});
31 changes: 0 additions & 31 deletions packages/docusaurus-mdx-loader/src/deps.d.ts

This file was deleted.

31 changes: 31 additions & 0 deletions packages/docusaurus-mdx-loader/src/frontMatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import {
JoiFrontMatter as Joi,
validateFrontMatter,
} from '@docusaurus/utils-validation';

export type MDXFrontMatter = {
format: 'md' | 'mdx' | 'detect';
};

export const DefaultMDXFrontMatter: MDXFrontMatter = {
format: 'detect',
};

const MDXFrontMatterSchema = Joi.object<MDXFrontMatter>({
format: Joi.string()
.equal('md', 'mdx', 'detect')
.default(DefaultMDXFrontMatter.format),
}).default(DefaultMDXFrontMatter);

export function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter {
return validateFrontMatter(frontMatter, MDXFrontMatterSchema, {
allowUnknown: false,
});
}
8 changes: 3 additions & 5 deletions packages/docusaurus-mdx-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import {mdxLoader} from './loader';

import type {TOCItem as TOCItemImported} from './remark/toc';

export default mdxLoader;

export type TOCItem = {
readonly value: string;
readonly id: string;
readonly level: number;
};
export type TOCItem = TOCItemImported;

export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
/** As verbatim declared in the MDX document. */
Expand Down
Loading