refactor(v2): shift to docusaurus/mdx-loader (#1339)

This commit is contained in:
Endilie Yacop Sucipto 2019-04-06 23:55:22 +07:00 committed by GitHub
parent 1a8e12048e
commit aa27f82acc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 40 deletions

View 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);
};