summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/remark-escape.ts
blob: 84cdf2efa7cccf1f5bec423c3c4762148f55c6ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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-legacy.
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, '-->');
	}
}