0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/markdown/remark/src/remark-expressions.ts
2021-12-22 16:11:05 -05:00

31 lines
1.1 KiB
TypeScript

// Vite bug: dynamically import() modules needed for CJS. Cache in memory to keep side effects
let mdxExpression: any;
let mdxExpressionFromMarkdown: any;
let mdxExpressionToMarkdown: any;
export function remarkExpressions(this: any, options: any) {
let settings = options || {};
let data = this.data();
add('micromarkExtensions', mdxExpression({}));
add('fromMarkdownExtensions', mdxExpressionFromMarkdown);
add('toMarkdownExtensions', mdxExpressionToMarkdown);
function add(field: any, value: any) {
/* istanbul ignore if - other extensions. */
if (data[field]) data[field].push(value);
else data[field] = [value];
}
}
export async function loadRemarkExpressions() {
if (!mdxExpression) {
const micromarkMdxExpression = await import('micromark-extension-mdx-expression');
mdxExpression = micromarkMdxExpression.mdxExpression;
}
if (!mdxExpressionFromMarkdown || !mdxExpressionToMarkdown) {
const mdastUtilMdxExpression = await import('mdast-util-mdx-expression');
mdxExpressionFromMarkdown = mdastUtilMdxExpression.mdxExpressionFromMarkdown;
mdxExpressionToMarkdown = mdastUtilMdxExpression.mdxExpressionToMarkdown;
}
}