Serve markdown versions of your HTML pages to AI agents and bots
spatie/laravel-markdown-response is a Laravel package for serve markdown versions of your html pages to ai agents and bots.
It currently has 75 GitHub stars and 49.521 downloads on Packagist (latest version 1.2.2).
Install it with composer require spatie/laravel-markdown-response.
Discover more Laravel packages by spatie
or browse all Laravel packages to compare alternatives.
Last updated
AI agents increasingly consume web content. This package lets your Laravel app serve markdown versions of HTML pages. Markdown requests are detected via Accept: text/markdown header, known AI user agent patterns, or .md URL suffix. The conversion is driver-based (local PHP or Cloudflare Workers AI), results are cached, and HTML can be preprocessed before conversion.
Here's a quick example:
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, they receive a clean markdown version of the page.
You can also convert HTML to markdown directly:
use Spatie\MarkdownResponse\Facades\Markdown;
$markdown = Markdown::convert($html);
And test your conversions:
use Spatie\MarkdownResponse\Facades\Markdown;
it('converts the about page to markdown', function () {
Markdown::fake();
$this->get('/about.md')->assertOk();
Markdown::assertConverted();
});
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
All documentation is available on our documentation site.
You can run the tests with:
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.