astro/packages/markdown/remark/src/rehype-expressions.ts
Nate Moore cfae9760b2
Improve Markdown + Components usage (#3410)
* feat: use internal MDX tooling for markdown + components

* fix: improve MD + component tests

* chore: add changeset

* fix: make tsc happy

* fix(#3319): add regression test for component children

* fix(markdown): support HTML comments in markdown

* fix(#2474): ensure namespaced components are properly handled in markdown pages

* fix(#3220): ensure html in markdown pages does not have extra surrounding space

* fix(#3264): ensure that remark files pass in file information

* fix(#3254): enable experimentalStaticExtraction for `.md` pages

* fix: revert parsing change

* fix: remove `markdown.mode` option
2022-05-24 17:02:11 -05:00

18 lines
490 B
TypeScript

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;
});
};
}