mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-31 15:29:32 +02:00
feat: support mermaid code blocks in Markdown (#7490)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
d2fdd981f7
commit
9c92a79d23
39 changed files with 1666 additions and 13 deletions
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* 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 {
|
||||
validateThemeConfig,
|
||||
DEFAULT_THEME_CONFIG,
|
||||
} from '../validateThemeConfig';
|
||||
import type {Joi} from '@docusaurus/utils-validation';
|
||||
import type {ThemeConfig, UserThemeConfig} from '@docusaurus/theme-mermaid';
|
||||
|
||||
function testValidateThemeConfig(themeConfig: UserThemeConfig) {
|
||||
function validate(
|
||||
schema: Joi.ObjectSchema<ThemeConfig>,
|
||||
cfg: UserThemeConfig,
|
||||
) {
|
||||
const {value, error} = schema.validate(cfg, {
|
||||
convert: false,
|
||||
});
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
return validateThemeConfig({validate, themeConfig});
|
||||
}
|
||||
|
||||
describe('validateThemeConfig', () => {
|
||||
it('undefined config', () => {
|
||||
const mermaid = undefined;
|
||||
expect(testValidateThemeConfig({mermaid})).toEqual(DEFAULT_THEME_CONFIG);
|
||||
});
|
||||
|
||||
it('nonexistent config', () => {
|
||||
expect(testValidateThemeConfig({})).toEqual(DEFAULT_THEME_CONFIG);
|
||||
});
|
||||
|
||||
it('empty config', () => {
|
||||
const mermaid = {};
|
||||
expect(testValidateThemeConfig({mermaid})).toEqual(DEFAULT_THEME_CONFIG);
|
||||
});
|
||||
|
||||
it('theme', () => {
|
||||
const mermaid = {
|
||||
theme: {
|
||||
light: 'light',
|
||||
dark: 'dark',
|
||||
},
|
||||
};
|
||||
expect(testValidateThemeConfig({mermaid})).toEqual({
|
||||
mermaid: {
|
||||
...DEFAULT_THEME_CONFIG.mermaid,
|
||||
...mermaid,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('mermaid options', () => {
|
||||
const mermaid = {
|
||||
options: {
|
||||
fontFamily: 'Ariel',
|
||||
},
|
||||
};
|
||||
expect(testValidateThemeConfig({mermaid})).toEqual({
|
||||
mermaid: {
|
||||
...DEFAULT_THEME_CONFIG.mermaid,
|
||||
...mermaid,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue