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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
490 B
TypeScript
Raw Normal View History

2021-07-07 20:10:09 +00:00
import { map } from 'unist-util-map';
export default function rehypeExpressions(): any {
2021-07-07 20:10:09 +00:00
return function (node: any): any {
return map(node, (child) => {
if (child.type === 'text') {
return { ...child, type: 'raw' };
}
if (child.type === 'mdxTextExpression') {
return { type: 'raw', value: `{${(child as any).value}}` };
}
if (child.type === 'mdxFlowExpression') {
return { type: 'raw', value: `{${(child as any).value}}` };
}
return child;
2021-07-07 20:10:09 +00:00
});
};
}