mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
16 lines
578 B
TypeScript
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);
|
|
};
|
|
};
|