New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

spatie/laravel-markdown-response

Serve markdown versions of your HTML pages to AI agents and bots
211,097 83
Install
composer require spatie/laravel-markdown-response
Latest Version:1.2.3
PHP:^8.4
Laravel:12 · 13
License:MIT
Last Updated:Oct 22, 2026
Links: GitHub  ·  Packagist
Maintainer: spatie
Logo for laravel-markdown-response

Serve markdown versions of your HTML pages to AI agents and bots

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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();
});

Support us

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.

Documentation

All documentation is available on our documentation site.

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Related Packages

spatie/laravel-mailcoach-markdown-editor

A Toast UI Markdown editor package for Mailcoach

242,871 7
spatie/commonmark-wire-navigate

Add a wire:navigate attribute to links rendered in Markdown

18,242 10
spatie/guidelines-skills

Spatie's coding guidelines as AI skills for Laravel Boost and skills.sh

317,235 97
spatie/elasticsearch-search-string-parser

Build Elasticsearch queries based of a query string

24,336 51
baconfy/prompt

Manage AI prompts in Laravel with Markdown + YAML front matter, multiple drivers...

1,467 3

Version History

Version Released PHP Laravel License
1.2.3 ^8.4 ^12.0 || ^13.0 MIT
1.2.2 ^8.4 ^12.0 || ^13.0 MIT
1.2.1 ^8.4 ^12.0 || ^13.0 MIT
1.2.0 ^8.4 ^12.0 || ^13.0 MIT
1.1.1 ^8.4 ^12.0 || ^13.0 MIT