astro/packages/markdown/remark/src/remark-escape.ts

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

16 lines
502 B
TypeScript
Raw Normal View History

import type { Literal } from 'unist';
2022-06-20 17:14:08 +00:00
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>) {
2022-06-20 17:14:08 +00:00
node.value = node.value.replace(/{\/\*<!--/gs, '<!--').replace(/-->\*\/}/gs, '-->');
}
}