Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Markdown Response Laravel Package

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.

View on GitHub
Deep Wiki
Context7

title: Choose a conversion driver weight: 3

By default, the package converts HTML to markdown locally using league/html-to-markdown. If you need better conversion quality or JavaScript rendering support, you can switch to an external driver.

Set the driver via the MARKDOWN_RESPONSE_DRIVER environment variable.

Use the League driver (default)

The League driver runs locally, requires no external services, and works out of the box.

MARKDOWN_RESPONSE_DRIVER=league

Options are passed directly to the HtmlConverter constructor. See the league/html-to-markdown documentation for available options.

// config/markdown-response.php

'driver_options' => [
    'league' => [
        'options' => [
            'strip_tags' => true,
            'hard_break' => true,
        ],
    ],
],

Use the Cloudflare driver

The Cloudflare driver uses the Workers AI API to convert HTML to markdown server-side. It sends the HTML as a file upload and returns the converted markdown.

MARKDOWN_RESPONSE_DRIVER=cloudflare
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_API_TOKEN=your-api-token

To get your credentials:

  1. Log in to the Cloudflare dashboard
  2. Your Account ID is in the dashboard URL
  3. Create an API token under Manage account > Account API tokens

Create a custom driver

You can create your own driver by implementing the MarkdownDriver interface:

namespace App\Drivers;

use Spatie\MarkdownResponse\Drivers\MarkdownDriver;

class PandocDriver implements MarkdownDriver
{
    public function convert(string $html): string
    {
        // Your conversion logic here
    }
}

Then bind it to the MarkdownDriver interface in a service provider:

use App\Drivers\PandocDriver;
use Spatie\MarkdownResponse\Drivers\MarkdownDriver;

$this->app->singleton(MarkdownDriver::class, PandocDriver::class);

Switch drivers at runtime

You can switch drivers on a per-conversion basis using the using() method:

use Spatie\MarkdownResponse\Facades\Markdown;

$markdown = Markdown::using('cloudflare')->convert($html);
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport