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