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