summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/rehype-expressions.ts
blob: f06f242e2b75bee298b398e6ab4d7feeedf880f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { map } from 'unist-util-map';

export default function rehypeExpressions(): any {
	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;
		});
	};
}