mirror of
https://github.com/withastro/astro.git
synced 2025-01-13 22:11:20 -05:00
72c7ae9901
* update formatter config * format --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
16 lines
583 B
TypeScript
16 lines
583 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> = () => {
|
|
return async (tree) => {
|
|
await highlightCodeBlocks(tree, (code, language) => {
|
|
let { html, classLanguage } = runHighlighterWithAstro(language, code);
|
|
|
|
return Promise.resolve(
|
|
`<pre class="${classLanguage}" data-language="${language}"><code is:raw class="${classLanguage}">${html}</code></pre>`,
|
|
);
|
|
});
|
|
};
|
|
};
|