Repository navigation
Reusing Astro's remark pipeline #16
Replies: 2 comments 1 reply
|
There isn’t an “automatic” way, but you can share the plugin pipeline across renderers.
|
|
You can read the existing configuration from an integration's I tested this with Astro 7.4.13 and @astrojs/markdown-remark 7.3.10 in an independent static import type { AstroIntegration } from 'astro';
import {
createMarkdownProcessor, isUnifiedProcessor,
type MarkdownRenderer,
} from '@astrojs/markdown-remark';
let includedRenderer: MarkdownRenderer | undefined;
const captureMarkdown: AstroIntegration = {
name: 'capture-existing-markdown-options',
hooks: {
'astro:config:done': async ({ config }) => {
const processor = config.markdown.processor;
if (!isUnifiedProcessor(processor)) throw new Error('Requires unified');
includedRenderer = await createMarkdownProcessor({
...config.markdown,
...processor.options,
gfm: processor.options.gfm ?? config.markdown.gfm,
smartypants: processor.options.smartypants ?? config.markdown.smartypants,
});
},
},
};Your include plugin can read The fixture verified the configured remark order and rehype plugin on the parent and two nested includes. Without the captured options, the child remained untransformed. This creates another HTML renderer, not access to Astro's active unified instance or a combined Markdown AST. So this addresses your follow-up about accessing the existing configuration. If the directive specifically requires a child's mdast, that AST integration remains a separate step. |
Uh oh!
There was an error while loading. Please reload this page.
For implementing an "include" markdown directive as a remark plugin, I need to parse a user-specified Markdown file path with the Astro's remark pipeline
Is there a way to invoke Astro's remark pipeline (and thus with all user-specified plugins in the config) without copy-pasting it?
All reactions