mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
13 lines
498 B
TypeScript
13 lines
498 B
TypeScript
|
import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter';
|
||
|
import type { Root } from 'hast';
|
||
|
import type { Plugin } from 'unified';
|
||
|
import { highlightCodeBlocks } from './highlight.js';
|
||
|
|
||
|
export const rehypePrism: Plugin<[], Root> = () => (tree) => {
|
||
|
highlightCodeBlocks(tree, (code, language) => {
|
||
|
let { html, classLanguage } = runHighlighterWithAstro(language, code);
|
||
|
|
||
|
return `<pre class="${classLanguage}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
|
||
|
});
|
||
|
};
|