astro/packages/markdown-support/src/remark-expressions.ts

20 lines
653 B
TypeScript
Raw Normal View History

2021-07-07 20:10:09 +00:00
import { mdxExpression } from 'micromark-extension-mdx-expression';
import { mdxExpressionFromMarkdown, mdxExpressionToMarkdown } from 'mdast-util-mdx-expression';
function remarkExpressions(this: any, options: any) {
2021-07-07 20:10:09 +00:00
let settings = options || {};
let data = this.data();
2021-07-07 20:10:09 +00:00
add('micromarkExtensions', mdxExpression({}));
add('fromMarkdownExtensions', mdxExpressionFromMarkdown);
add('toMarkdownExtensions', mdxExpressionToMarkdown);
function add(field: any, value: any) {
/* istanbul ignore if - other extensions. */
2021-07-07 20:10:09 +00:00
if (data[field]) data[field].push(value);
else data[field] = [value];
}
}
export default remarkExpressions;