mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
refactor(v2): shift to docusaurus/mdx-loader (#1339)
This commit is contained in:
parent
1a8e12048e
commit
aa27f82acc
8 changed files with 179 additions and 40 deletions
38
packages/docusaurus-mdx-loader/src/index.js
Normal file
38
packages/docusaurus-mdx-loader/src/index.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright (c) 2017-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
const {getOptions} = require('loader-utils');
|
||||
const mdx = require('@mdx-js/mdx');
|
||||
const rehypePrism = require('@mapbox/rehype-prism');
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
rehypePlugins: [[rehypePrism, {ignoreMissing: true}]],
|
||||
prismTheme: 'prism-themes/themes/prism-atom-dark.css',
|
||||
};
|
||||
|
||||
module.exports = async function(content) {
|
||||
const callback = this.async();
|
||||
|
||||
const options = Object.assign(DEFAULT_OPTIONS, getOptions(this), {
|
||||
filepath: this.resourcePath,
|
||||
});
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = await mdx(content, options);
|
||||
} catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
const code = `
|
||||
import React from 'react';
|
||||
import { mdx } from '@mdx-js/react';
|
||||
import '${options.prismTheme}';
|
||||
${result}
|
||||
`;
|
||||
|
||||
return callback(null, code);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue