mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
ccafa8d230
* Update highlight.ts * Create cold-snakes-train.md * Update Code.astro Solution for use-case described in withastro/roadmap#276 (https://github.com/withastro/roadmap/discussions/276) * roll-back initial fix * new fix * update changeset * Update packages/markdown/remark/src/rehype-prism.ts * Update .changeset/cold-snakes-train.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/cold-snakes-train.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/cold-snakes-train.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/cold-snakes-train.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Matthew Phillips <matthew@matthewphillips.info> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
16 lines
582 B
TypeScript
16 lines
582 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>`
|
|
);
|
|
});
|
|
};
|
|
};
|