Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const mdxTranspileAsync = async (mdxText: string, isEntry: boolean, preview: Preview) => {
let mdxTextToCompile: string;
if (!hasDefaultExport(mdxText)) {
// inject vscode markdown styles if we haven't found a default export
mdxTextToCompile = injectMDXStyles(mdxText, preview);
} else {
mdxTextToCompile = mdxText;
}
const compiledMDX = await mdx(mdxTextToCompile);
return wrapCompiledMdx(compiledMDX, isEntry);
};
export const renderToString = async (
source: Buffer | string,
{ components, mdxOptions, scope = {} }: MarkdownRenderConfig
): Promise => {
// transform it into react
const code = await mdx(source, { ...mdxOptions, skipExport: true });
// mdx gives us back es6 code, we then need to transform into two formats:
// - first a version we can render to string right now as a "serialized" result
// - next a version that is fully browser-compatible that we can eval to rehydrate
// this one is for immediate evaluation so we can renderToString below
const now = await transformAsync(code, {
presets: [presetReact, presetEnv],
configFile: false,
});
// this one is for the browser to eval and rehydrate, later
const later = await transformAsync(code, {
presets: [presetReact, presetEnv],
plugins: [pluginBrowser],
configFile: false,