aboutsummaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/rehype-prism.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown/remark/src/rehype-prism.ts')
-rw-r--r--packages/markdown/remark/src/rehype-prism.ts20
1 files changed, 20 insertions, 0 deletions
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(
+ `<pre class="${classLanguage}" data-language="${language}"><code is:raw class="${classLanguage}">${html}</code></pre>`,
+ );
+ },
+ excludeLangs,
+ );
+ };
+};