From e586d7d704d475afe3373a1de6ae20d504f79d6d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 14:25:23 +0000 Subject: Sync from a8e1c0a7402940e0fc5beef669522b315052df1b --- packages/markdown/remark/src/rehype-prism.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/markdown/remark/src/rehype-prism.ts (limited to 'packages/markdown/remark/src/rehype-prism.ts') diff --git a/packages/markdown/remark/src/rehype-prism.ts b/packages/markdown/remark/src/rehype-prism.ts new file mode 100644 index 000000000..887a0a4b9 --- /dev/null +++ b/packages/markdown/remark/src/rehype-prism.ts @@ -0,0 +1,20 @@ +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<[string[]?], Root> = (excludeLangs) => { + return async (tree) => { + await highlightCodeBlocks( + tree, + (code, language) => { + let { html, classLanguage } = runHighlighterWithAstro(language, code); + + return Promise.resolve( + `
${html}
`,
+ );
+ },
+ excludeLangs,
+ );
+ };
+};
--
cgit v1.2.3