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 clean markdown versions of your Laravel HTML pages for AI agents and bots. Detects requests via Accept: text/markdown, known user agents, or .md URLs. Driver-based conversion (local PHP or Cloudflare Workers AI), caching, and HTML preprocessing included.

View on GitHub
Deep Wiki
Context7

title: Clean up HTML with preprocessors weight: 1

Before HTML is converted to markdown, it runs through preprocessors that strip elements which don't belong in a markdown document, like scripts, navigation menus, or advertising.

The package ships with four preprocessors:

  • RemoveScriptsAndStylesPreprocessor: strips <script> tags, <style> tags, and stylesheet <link> tags. Enabled by default.
  • RemoveNavigationPreprocessor: strips <nav> elements. Not enabled by default.
  • RemoveHeaderPreprocessor: strips <header> elements. Not enabled by default.
  • RemoveFooterPreprocessor: strips <footer> elements. Not enabled by default.

You can configure which preprocessors run in the config file:

// config/markdown-response.php

'preprocessors' => [
    Spatie\MarkdownResponse\Preprocessors\RemoveScriptsAndStylesPreprocessor::class,
    Spatie\MarkdownResponse\Preprocessors\RemoveNavigationPreprocessor::class,
],

Preprocessors run in the order they are listed.

Create a custom preprocessor

A preprocessor is an invokable class that implements the Preprocessor interface:

namespace App\Preprocessors;

use Spatie\MarkdownResponse\Preprocessors\Preprocessor;

class RemoveAds implements Preprocessor
{
    public function __invoke(string $html): string
    {
        return preg_replace('/<div\b[^>]*class="[^"]*\bad\b[^"]*"[^>]*>.*?<\/div>/is', '', $html);
    }
}

Then register it in the config file:

// config/markdown-response.php

'preprocessors' => [
    Spatie\MarkdownResponse\Preprocessors\RemoveScriptsAndStylesPreprocessor::class,
    App\Preprocessors\RemoveAds::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.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope