18 lines
510 B
TypeScript
18 lines
510 B
TypeScript
|
import { visit } from 'unist-util-visit';
|
||
|
import type { Literal } from 'unist';
|
||
|
|
||
|
// 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, '-->');
|
||
|
}
|
||
|
}
|