https://github.com/spatie/laravel-markdown-response
Serve markdown versions of your HTML pages to AI agents and bots
https://github.com/spatie/laravel-markdown-response
ai laravel markdown php
Last synced: 4 months ago
JSON representation
Serve markdown versions of your HTML pages to AI agents and bots
- Host: GitHub
- URL: https://github.com/spatie/laravel-markdown-response
- Owner: spatie
- License: mit
- Created: 2026-02-16T21:07:55.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-02-19T16:44:54.000Z (4 months ago)
- Last Synced: 2026-02-21T20:37:09.807Z (4 months ago)
- Topics: ai, laravel, markdown, php
- Language: PHP
- Homepage: https://spatie.be/docs/laravel-markdown-response
- Size: 91.8 KB
- Stars: 40
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Support: docs/support-us.md
Awesome Lists containing this project
README
Serve markdown versions of your HTML pages to AI agents and bots
[](https://packagist.org/packages/spatie/laravel-markdown-response)
[](https://github.com/spatie/laravel-markdown-response/actions?query=workflow%3Arun-tests+branch%3Amain)
[](https://github.com/spatie/laravel-markdown-response/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[](https://packagist.org/packages/spatie/laravel-markdown-response)
AI agents increasingly consume web content. This package lets your Laravel app serve markdown versions of HTML pages — detected via `Accept: text/markdown` header, known AI user agent patterns, or `.md` URL suffix. The conversion is driver-based (local PHP, Cloudflare Workers AI, or markdown.new), results are cached, and HTML can be preprocessed before conversion.
Here's a quick example:
```php
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:
```php
use Spatie\MarkdownResponse\Facades\Markdown;
$markdown = Markdown::convert($html);
```
And test your conversions:
```php
use Spatie\MarkdownResponse\Facades\Markdown;
it('converts the about page to markdown', function () {
Markdown::fake();
$this->get('/about.md')->assertOk();
Markdown::assertConverted();
});
```
## Support us
[
](https://spatie.be/github-ad-click/laravel-markdown-response)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Documentation
All documentation is available [on our documentation site](https://spatie.be/docs/laravel-markdown-response).
## Testing
You can run the tests with:
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.