Home / Function/ createMarkdownProcessor() — astro Function Reference

createMarkdownProcessor() — astro Function Reference

Architecture documentation for the createMarkdownProcessor() function in index.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  aae36f52_cdac_44a0_4252_547d557d1d35["createMarkdownProcessor()"]
  69f93a80_1603_3b35_46fa_5fc7b973b199["index.ts"]
  aae36f52_cdac_44a0_4252_547d557d1d35 -->|defined in| 69f93a80_1603_3b35_46fa_5fc7b973b199
  3d8168f3_300a_12a4_6a4d_d4c08a494e09["prefixError()"]
  aae36f52_cdac_44a0_4252_547d557d1d35 -->|calls| 3d8168f3_300a_12a4_6a4d_d4c08a494e09
  style aae36f52_cdac_44a0_4252_547d557d1d35 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/markdown/remark/src/index.ts lines 70–175

export async function createMarkdownProcessor(
	opts?: AstroMarkdownProcessorOptions,
): Promise<MarkdownProcessor> {
	const {
		syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
		shikiConfig = markdownConfigDefaults.shikiConfig,
		remarkPlugins = markdownConfigDefaults.remarkPlugins,
		rehypePlugins = markdownConfigDefaults.rehypePlugins,
		remarkRehype: remarkRehypeOptions = markdownConfigDefaults.remarkRehype,
		gfm = markdownConfigDefaults.gfm,
		smartypants = markdownConfigDefaults.smartypants,
	} = opts ?? {};

	const loadedRemarkPlugins = await Promise.all(loadPlugins(remarkPlugins));
	const loadedRehypePlugins = await Promise.all(loadPlugins(rehypePlugins));

	const parser = unified().use(remarkParse);

	// gfm and smartypants
	if (!isPerformanceBenchmark) {
		if (gfm) {
			parser.use(remarkGfm);
		}
		if (smartypants) {
			parser.use(remarkSmartypants);
		}
	}

	// User remark plugins
	for (const [plugin, pluginOpts] of loadedRemarkPlugins) {
		parser.use(plugin, pluginOpts);
	}

	if (!isPerformanceBenchmark) {
		// Apply later in case user plugins resolve relative image paths
		parser.use(remarkCollectImages, opts?.image);
	}

	// Remark -> Rehype
	parser.use(remarkRehype, {
		allowDangerousHtml: true,
		passThrough: [],
		...remarkRehypeOptions,
	});

	if (syntaxHighlight && !isPerformanceBenchmark) {
		const syntaxHighlightType =
			typeof syntaxHighlight === 'string' ? syntaxHighlight : syntaxHighlight?.type;
		const excludeLangs =
			typeof syntaxHighlight === 'object' ? syntaxHighlight?.excludeLangs : undefined;
		// Syntax highlighting
		if (syntaxHighlightType === 'shiki') {
			parser.use(rehypeShiki, shikiConfig, excludeLangs);
		} else if (syntaxHighlightType === 'prism') {
			parser.use(rehypePrism, excludeLangs);
		}
	}

	// User rehype plugins
	for (const [plugin, pluginOpts] of loadedRehypePlugins) {
		parser.use(plugin, pluginOpts);
	}

	// Images / Assets support
	parser.use(rehypeImages);

	// Headings
	if (!isPerformanceBenchmark) {
		parser.use(rehypeHeadingIds);
	}

	// Stringify to HTML
	parser.use(rehypeRaw).use(rehypeStringify, { allowDangerousHtml: true });

	return {
		async render(content, renderOpts) {
			const vfile = new VFile({
				value: content,
				path: renderOpts?.fileURL,
				data: {
					astro: {

Domain

Subdomains

Frequently Asked Questions

What does createMarkdownProcessor() do?
createMarkdownProcessor() is a function in the astro codebase, defined in packages/markdown/remark/src/index.ts.
Where is createMarkdownProcessor() defined?
createMarkdownProcessor() is defined in packages/markdown/remark/src/index.ts at line 70.
What does createMarkdownProcessor() call?
createMarkdownProcessor() calls 1 function(s): prefixError.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free