mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
fix: allow html syntax in MDX v2 with format md (#8960)
* attempt to support html embeds in mdx with format md * refactor mdx loader + support embedding html in commonmark thanks to rehype-raw * extract processor code * refactor processor code * extract format + unit test * try to refactor processor * try to refactor processor * adjust md page * do not apply rehype-raw when format is mdx * fix lint issue
This commit is contained in:
parent
af9a4f2a2e
commit
07ad635b69
11 changed files with 491 additions and 173 deletions
52
packages/docusaurus-mdx-loader/src/__tests__/format.test.ts
Normal file
52
packages/docusaurus-mdx-loader/src/__tests__/format.test.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* 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 {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',
|
||||
);
|
||||
});
|
||||
|
||||
it('detects appropriate format from file extension', () => {
|
||||
expect(getFormat({frontMatterFormat: 'detect', filePath: 'xyz.md'})).toBe(
|
||||
'md',
|
||||
);
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'xyz.markdown'}),
|
||||
).toBe('md');
|
||||
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.md'}),
|
||||
).toBe('md');
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.markdown'}),
|
||||
).toBe('md');
|
||||
expect(getFormat({frontMatterFormat: 'detect', filePath: 'xyz.mdx'})).toBe(
|
||||
'mdx',
|
||||
);
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.mdx'}),
|
||||
).toBe('mdx');
|
||||
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'xyz.unknown'}),
|
||||
).toBe('mdx');
|
||||
expect(
|
||||
getFormat({frontMatterFormat: 'detect', filePath: 'folder/xyz.unknown'}),
|
||||
).toBe('mdx');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue