astro/packages/markdown/remark/src/remark-escape.ts
2022-06-20 17:14:08 +00:00

15 lines
502 B
TypeScript

import type { Literal } from 'unist';
import { visit } from 'unist-util-visit';
// In code blocks, this removes the JS comment wrapper added to
// HTML comments by vite-plugin-markdown.
export default function remarkEscape() {
return (tree: any) => {
visit(tree, 'code', removeCommentWrapper);
visit(tree, 'inlineCode', removeCommentWrapper);
};
function removeCommentWrapper(node: Literal<string>) {
node.value = node.value.replace(/{\/\*<!--/gs, '<!--').replace(/-->\*\/}/gs, '-->');
}
}