spatie/laravel-markdown-response
Serve markdown versions of your Laravel HTML pages for AI agents and bots. Detect markdown requests via Accept: text/markdown, known user agents, or .md URLs. Driver-based conversion (local PHP or Cloudflare Workers AI), with caching and HTML preprocessing.
AI agents increasingly consume web content. This package lets your Laravel app serve markdown versions of HTML pages, making your content more accessible to AI crawlers and tools.
Add the middleware to your routes, and you're done:
use Spatie\MarkdownResponse\Middleware\ProvideMarkdownResponse;
Route::middleware(ProvideMarkdownResponse::class)->group(function () {
Route::get('/about', [PageController::class, 'show']);
Route::get('/posts/{post}', [PostController::class, 'show']);
});
Now when an AI agent visits /about (or a user visits /about.md), it receives a clean markdown version of the page instead of HTML. Your existing controllers and views stay exactly the same.
The package detects markdown requests through three mechanisms: Accept: text/markdown headers, .md URL suffixes, and known AI bot user agents like GPTBot and ClaudeBot.
The HTML-to-markdown conversion is driver-based. The default driver uses league/html-to-markdown and works locally without any external services. You can also use the Cloudflare Workers AI API for better conversion quality.
Converted responses are cached by default, so repeated requests skip the conversion entirely.
How can I help you explore Laravel packages today?