astro/packages/integrations/mdx/src/remark-prism.ts

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

19 lines
526 B
TypeScript
Raw Normal View History

import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter';
import { visit } from 'unist-util-visit';
/** */
export default function remarkPrism() {
2022-07-21 20:46:16 +00:00
return (tree: any) =>
visit(tree, 'code', (node: any) => {
let { lang, value } = node;
node.type = 'html';
let { html, classLanguage } = runHighlighterWithAstro(lang, value);
2022-07-21 20:46:16 +00:00
let classes = [classLanguage];
node.value = `<pre class="${classes.join(
' '
)}"><code class="${classLanguage}">${html}</code></pre>`;
return node;
});
}