0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-03 22:29:08 -05:00
astro/packages/markdown/remark/src/rehype-shiki.ts

16 lines
578 B
TypeScript

import type { Root } from 'hast';
import type { Plugin } from 'unified';
import { highlightCodeBlocks } from './highlight.js';
import { type ShikiHighlighter, createShikiHighlighter } from './shiki.js';
import type { ShikiConfig } from './types.js';
export const rehypeShiki: Plugin<[ShikiConfig?], Root> = (config) => {
let highlighterAsync: Promise<ShikiHighlighter> | undefined;
return async (tree) => {
highlighterAsync ??= createShikiHighlighter(config);
const highlighter = await highlighterAsync;
await highlightCodeBlocks(tree, highlighter.highlight);
};
};