mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
feat(mdx): add siteConfig.markdown.format to configure the default content parser (MDX / CommonMark) (#9097)
This commit is contained in:
parent
be4e67caa9
commit
cc6d9696f0
21 changed files with 304 additions and 83 deletions
|
@ -9,44 +9,126 @@ import {getFormat} from '../format';
|
|||
|
||||
describe('getFormat', () => {
|
||||
it('uses frontMatter format over anything else', () => {
|
||||
expect(getFormat({frontMatterFormat: 'md', filePath: 'xyz.md'})).toBe('md');
|
||||
expect(getFormat({frontMatterFormat: 'md', filePath: 'xyz.mdx'})).toBe(
|
||||
'md',
|
||||
);
|
||||
expect(getFormat({frontMatterFormat: 'mdx', filePath: 'xyz.md'})).toBe(
|
||||
'mdx',
|
||||
);
|
||||
expect(getFormat({frontMatterFormat: 'mdx', filePath: 'xyz.mdx'})).toBe(
|
||||
'mdx',
|
||||
);
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'md',
|
||||
filePath: 'xyz.md',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'md',
|
||||
filePath: 'xyz.mdx',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'mdx',
|
||||
filePath: 'xyz.md',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'mdx',
|
||||
filePath: 'xyz.mdx',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
});
|
||||
|
||||
it('detects appropriate format from file extension', () => {
|
||||
expect(getFormat({frontMatterFormat: 'detect', filePath: 'xyz.md'})).toBe(
|
||||
'md',
|
||||
);
|
||||
it('supports "detects" for front matter', () => {
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'xyz.markdown'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'xyz.md',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'xyz.markdown',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.md'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'folder/xyz.md',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.markdown'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'folder/xyz.markdown',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(getFormat({frontMatterFormat: 'detect', filePath: 'xyz.mdx'})).toBe(
|
||||
'mdx',
|
||||
);
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.mdx'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'xyz.mdx',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'folder/xyz.mdx',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'xyz.unknown'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'xyz.unknown',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.unknown'}),
|
||||
getFormat({
|
||||
frontMatterFormat: 'detect',
|
||||
filePath: 'folder/xyz.unknown',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
});
|
||||
|
||||
it('fallbacks to markdown config format when front matter undefined', () => {
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: undefined,
|
||||
filePath: 'xyz.md',
|
||||
markdownConfigFormat: 'mdx',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: undefined,
|
||||
filePath: 'xyz.mdx',
|
||||
markdownConfigFormat: 'md',
|
||||
}),
|
||||
).toBe('md');
|
||||
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: undefined,
|
||||
filePath: 'xyz.md',
|
||||
markdownConfigFormat: 'detect',
|
||||
}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({
|
||||
frontMatterFormat: undefined,
|
||||
filePath: 'xyz.mdx',
|
||||
markdownConfigFormat: 'detect',
|
||||
}),
|
||||
).toBe('mdx');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue