mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat: upgrade to MDX v2 (#8288)
Co-authored-by: Armano <armano2@users.noreply.github.com>
This commit is contained in:
parent
10f161d578
commit
bf913aea2a
161 changed files with 4028 additions and 2821 deletions
|
@ -2,27 +2,19 @@
|
|||
|
||||
exports[`validation schemas admonitionsSchema: for value=[] 1`] = `""value" does not look like a valid admonitions config"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"customTypes":{"myKeyword":{"keyword":"myKeyword","infima":true,"svg":"<svg width=\\"512px\\" height=\\"512px\\" viewBox=\\"0 0 512 512\\" xmlns=\\"http://www.w3.org/2000/svg\\"></svg>"}}} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "customTypes" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"customTypes":{"myKeyword":{"keyword":"myKeyword","infima":true,"svg":"<svg width=\\"512px\\" height=\\"512px\\" viewBox=\\"0 0 512 512\\" xmlns=\\"http://www.w3.org/2000/svg\\"></svg>"}}} 1`] = `""customTypes" is not allowed"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"icons":"emoji"} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "icons" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"icons":"emoji"} 1`] = `""icons" is not allowed"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"infima":true} 1`] = `
|
||||
"The Docusaurus admonitions system has changed, and the option "infima" does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions."
|
||||
`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"infima":true} 1`] = `""infima" is not allowed"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"keywords":["custom-keyword"],"extendDefaults":42} 1`] = `""extendDefaults" must be a boolean"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"tag":""} 1`] = `""tag" is not allowed to be empty"`;
|
||||
exports[`validation schemas admonitionsSchema: for value={"tag":""} 1`] = `"It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"tag":"+++","keywords":["info","tip"]} 1`] = `"It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"tag":"+++"} 1`] = `"It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)"`;
|
||||
|
||||
exports[`validation schemas admonitionsSchema: for value={"unknownAttribute":"val"} 1`] = `""unknownAttribute" is not allowed"`;
|
||||
|
||||
|
|
|
@ -97,22 +97,22 @@ describe('validation schemas', () => {
|
|||
testOK(true);
|
||||
testOK(false);
|
||||
testOK({});
|
||||
testOK({tag: '+++'});
|
||||
testOK({keywords: ['info', 'tip']});
|
||||
testOK({keywords: ['info', 'tip'], extendDefaults: true});
|
||||
testOK({keywords: ['info', 'tip'], extendDefaults: false});
|
||||
testOK({keywords: []});
|
||||
testOK({keywords: [], extendDefaults: true}); // noop
|
||||
testOK({keywords: [], extendDefaults: false}); // disable admonitions
|
||||
testOK({tag: '+++', keywords: ['info', 'tip']});
|
||||
testOK({tag: '+++', keywords: ['custom-keyword'], extendDefaults: true});
|
||||
testOK({tag: '+++', keywords: ['custom-keyword'], extendDefaults: false});
|
||||
testOK({keywords: ['custom-keyword'], extendDefaults: true});
|
||||
testOK({keywords: ['custom-keyword'], extendDefaults: false});
|
||||
|
||||
testFail(3);
|
||||
testFail([]);
|
||||
testFail({unknownAttribute: 'val'});
|
||||
testFail({tag: ''});
|
||||
testFail({keywords: ['custom-keyword'], extendDefaults: 42});
|
||||
testFail({tag: '+++'});
|
||||
testFail({tag: '+++', keywords: ['info', 'tip']});
|
||||
|
||||
// Legacy types
|
||||
testFail({
|
||||
|
|
|
@ -37,17 +37,10 @@ const MarkdownPluginsSchema = Joi.array()
|
|||
export const RemarkPluginsSchema = MarkdownPluginsSchema;
|
||||
export const RehypePluginsSchema = MarkdownPluginsSchema;
|
||||
|
||||
const LegacyAdmonitionConfigSchema = Joi.forbidden().messages({
|
||||
'any.unknown': `The Docusaurus admonitions system has changed, and the option {#label} does not exist anymore.
|
||||
You now need to swizzle the admonitions component to provide UI customizations such as icons.
|
||||
Please refer to https://github.com/facebook/docusaurus/pull/7152 for detailed upgrade instructions.`,
|
||||
});
|
||||
|
||||
export const AdmonitionsSchema = JoiFrontMatter.alternatives()
|
||||
.try(
|
||||
JoiFrontMatter.boolean().required(),
|
||||
JoiFrontMatter.object({
|
||||
tag: JoiFrontMatter.string(),
|
||||
keywords: JoiFrontMatter.array().items(
|
||||
JoiFrontMatter.string(),
|
||||
// Apparently this is how we tell job to accept empty arrays...
|
||||
|
@ -55,10 +48,10 @@ export const AdmonitionsSchema = JoiFrontMatter.alternatives()
|
|||
),
|
||||
extendDefaults: JoiFrontMatter.boolean(),
|
||||
|
||||
// TODO Remove before 2023
|
||||
customTypes: LegacyAdmonitionConfigSchema,
|
||||
icons: LegacyAdmonitionConfigSchema,
|
||||
infima: LegacyAdmonitionConfigSchema,
|
||||
// TODO Remove before 2024
|
||||
tag: Joi.any().forbidden().messages({
|
||||
'any.unknown': `It is not possible anymore to use a custom admonition tag. The only admonition tag supported is ':::' (Markdown Directive syntax)`,
|
||||
}),
|
||||
}).required(),
|
||||
)
|
||||
.default(true)
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import logger from '@docusaurus/logger';
|
||||
import Yaml from 'js-yaml';
|
||||
import {PluginIdSchema} from './validationSchemas';
|
||||
import type {ValidationOptions} from 'joi';
|
||||
import type Joi from './Joi';
|
||||
|
||||
/** Print warnings returned from Joi validation. */
|
||||
|
@ -77,13 +78,15 @@ export function normalizeThemeConfig<T>(
|
|||
* Validate front matter with better error message
|
||||
*/
|
||||
export function validateFrontMatter<T>(
|
||||
frontMatter: {[key: string]: unknown},
|
||||
frontMatter: unknown,
|
||||
schema: Joi.ObjectSchema<T>,
|
||||
options?: ValidationOptions,
|
||||
): T {
|
||||
const {value, error, warning} = schema.validate(frontMatter, {
|
||||
convert: true,
|
||||
allowUnknown: true,
|
||||
abortEarly: false,
|
||||
...options,
|
||||
});
|
||||
|
||||
printWarning(warning);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue