mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
a31bbd7ff8
* fix(markdown): don’t generate mdast html nodes `html` nodes from mdast are converted to `raw` hast nodes. These nodes are then not processed by proper rehype plugins. Typically if a remark plugin generates `html` nodes, this indicates it should have actually been a rehype plugin. This changes the remark plugins that generate `html` nodes into rehype nodes. These were `remarkPrism` and `remarkShiki`. Closes #9909 * Apply suggestions from code review * refactor(mdx): move user defined rehype plugins after syntax highlighting * fix(mdx): fix issue in mdx rehype plugin ordering * docs: explain why html/raw nodes are avoided in changeset This also includes some hints on what users could do to upgrade of they rely on these nodes. * Fix MDX rehype plugin ordering * refactor(remark): restore remarkPrism and remarkShiki They aren’t used anymore, but removing would be a breaking change. * chore: mark deprecated * Apply suggestions from code review Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * Update .changeset/thirty-beds-smoke.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
12 lines
498 B
TypeScript
12 lines
498 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> = () => (tree) => {
|
|
highlightCodeBlocks(tree, (code, language) => {
|
|
let { html, classLanguage } = runHighlighterWithAstro(language, code);
|
|
|
|
return `<pre class="${classLanguage}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
|
|
});
|
|
};
|