Astro's internal markdown processing library that provides a unified markdown processor built on remark and rehype ecosystem plugins with syntax highlighting, frontmatter parsing, and image processing capabilities.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Built-in remark plugins for image collection and other content processing tasks within the markdown processing pipeline.
Collects local and remote image paths from markdown content for processing and optimization.
/**
* Collect local and remote image paths from markdown
* @param opts - Image processing configuration options
* @returns Remark plugin function
*/
function remarkCollectImages(
opts?: AstroMarkdownProcessorOptions['image']
): Plugin<[AstroMarkdownProcessorOptions['image']?], mdast.Root>;Usage Examples:
import { createMarkdownProcessor, remarkCollectImages } from "@astrojs/markdown-remark";
// Using in processor configuration (automatic by default)
const processor = await createMarkdownProcessor({
remarkPlugins: [
[remarkCollectImages, {
domains: ['example.com', 'cdn.example.com'],
remotePatterns: [
{
protocol: 'https',
hostname: '**.github.com'
},
{
protocol: 'https',
hostname: 'images.unsplash.com'
}
]
}]
]
});
const result = await processor.render(`
# My Blog Post





[Link with image]: ./assets/linked-image.png
`);
console.log(result.metadata.localImagePaths);
// ['./screenshots/app.png', '../assets/avatar.jpg', './assets/linked-image.png']
console.log(result.metadata.remoteImagePaths);
// ['https://example.com/hero.jpg', 'https://github.com/user/repo/raw/main/image.png']
// The disallowed remote image is not included in remoteImagePathsFeatures:
Configuration options for image processing and validation.
interface ImageOptions {
/** Array of allowed domains for remote images */
domains?: string[];
/** Array of remote patterns for flexible hostname matching */
remotePatterns?: RemotePattern[];
}
interface RemotePattern {
/** Hostname pattern with wildcard support */
hostname?: string;
/** Optional pathname pattern */
pathname?: string;
/** Protocol to match (without trailing colon) */
protocol?: string;
/** Optional port number */
port?: string;
}Usage Examples:
import { createMarkdownProcessor } from "@astrojs/markdown-remark";
const processor = await createMarkdownProcessor({
image: {
// Simple domain allowlist
domains: [
'example.com',
'www.example.com',
'cdn.example.com',
'images.unsplash.com'
],
// Pattern-based matching
remotePatterns: [
// Allow all GitHub domains
{
protocol: 'https',
hostname: '**.github.com'
},
// Allow specific subdomain patterns
{
protocol: 'https',
hostname: 'img*.example.com'
},
// Allow with specific port
{
protocol: 'http',
hostname: 'localhost',
port: '3000'
},
// Allow with pathname pattern
{
protocol: 'https',
hostname: 'api.example.com',
pathname: '/images/**'
}
]
}
});The plugin follows specific logic for categorizing images:
URL Parsing: Attempts to parse the image source as a URL
Local vs Remote:
/ → treat as local/ → treat as absolute path (not collected)Validation:
Examples:
// Local images (collected)
 // Relative path
 // Parent directory
 // Subdirectory
// Absolute paths (not collected)
 // Root-relative
// Remote images (collected if allowed)
 // If example.com in domains
 // If **.github.com pattern exists
// Invalid/disallowed (ignored)
 // If random.com not allowed
 // Invalid URL formatThe collected image paths are used by downstream processing:
const result = await processor.render(markdown);
// Access collected paths
const localImages = result.metadata.localImagePaths;
const remoteImages = result.metadata.remoteImagePaths;
// These are later used by:
// 1. rehypeImages plugin for optimization metadata
// 2. Astro's image processing pipeline
// 3. Build-time image optimizationThe plugin supports various markdown image syntaxes:

![Alt text][ref]
![Alt text][ref "Title"]
[ref]: image.png
[ref]: image.png "Title"<img src="image.png" alt="Alt text">All formats are processed and their sources extracted for collection.
The plugin is designed to be fault-tolerant:
This ensures the markdown processing pipeline continues even with problematic image references.