summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src/remark-prism.ts
blob: 7dc05f358421c61010037b2da5eef09e167c0900 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter';
import { visit } from 'unist-util-visit';

/**  */
export default function remarkPrism() {
	return (tree: any) =>
		visit(tree, 'code', (node: any) => {
			let { lang, value } = node;
			node.type = 'html';

			let { html, classLanguage } = runHighlighterWithAstro(lang, value);
			let classes = [classLanguage];
			node.value = `<pre class="${classes.join(
				' '
			)}"><code class="${classLanguage}">${html}</code></pre>`;
			return node;
		});
}