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.
To verify your markdown conversion works correctly in tests, you can fake the Markdown facade. This prevents actual HTML-to-markdown conversion and lets you make assertions about what was converted.
use Spatie\MarkdownResponse\Facades\Markdown;
beforeEach(function () {
Markdown::fake();
});
Use assertConverted to verify that at least one conversion took place:
Markdown::fake();
$this->get('/about.md')->assertOk();
Markdown::assertConverted();
You can pass a callable for more specific assertions. The callable receives the HTML string:
Markdown::assertConverted(fn (string $html) => str_contains($html, '<h1>About</h1>'));
Use assertNotConverted to verify that no conversions were made:
Markdown::fake();
$this->get('/about')->assertOk();
Markdown::assertNotConverted();
Use assertConvertedCount to verify the exact number of conversions:
Markdown::fake();
$this->get('/about.md');
$this->get('/posts/1.md');
$this->get('/posts/2.md');
Markdown::assertConvertedCount(3);
How can I help you explore Laravel packages today?