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: Clean up markdown with postprocessors weight: 2

After HTML is converted to markdown, the result runs through postprocessors. These clean up the markdown output, for example by removing leftover HTML tags or collapsing excessive blank lines.

The package ships with two postprocessors:

  • RemoveHtmlTagsPostprocessor: strips any HTML tags that survived the conversion, such as <span> tags from syntax highlighting. Enabled by default.
  • CollapseBlankLinesPostprocessor: reduces three or more consecutive blank lines to a single blank line, and trims leading/trailing whitespace. Enabled by default.

You can configure which postprocessors run in the config file:

// config/markdown-response.php

'postprocessors' => [
    Spatie\MarkdownResponse\Postprocessors\RemoveHtmlTagsPostprocessor::class,
    Spatie\MarkdownResponse\Postprocessors\CollapseBlankLinesPostprocessor::class,
],

Postprocessors run in the order they are listed.

Create a custom postprocessor

A postprocessor is an invokable class that implements the Postprocessor interface:

namespace App\Postprocessors;

use Spatie\MarkdownResponse\Postprocessors\Postprocessor;

class AddFrontMatter implements Postprocessor
{
    public function __invoke(string $markdown): string
    {
        return "---\nsource: my-app\n---\n\n" . $markdown;
    }
}

Then register it in the config file:

// config/markdown-response.php

'postprocessors' => [
    Spatie\MarkdownResponse\Postprocessors\RemoveHtmlTagsPostprocessor::class,
    Spatie\MarkdownResponse\Postprocessors\CollapseBlankLinesPostprocessor::class,
    App\Postprocessors\AddFrontMatter::class,
],
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