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

Technical Evaluation

Architecture Fit

  • Pros:

    • Non-intrusive: Leverages middleware and facade patterns, requiring minimal changes to existing controllers/views.
    • AI-first optimization: Aligns with modern trends (e.g., AI agents consuming structured content) without disrupting traditional HTML workflows.
    • Extensible: Supports custom drivers (e.g., Cloudflare Workers AI) and cache key generators, enabling tailored performance/cost tradeoffs.
    • Laravel-native: Integrates seamlessly with Laravel’s middleware stack, caching systems, and testing utilities (e.g., Markdown::fake()).
    • Selective conversion: Skips non-HTML responses (JSON, redirects, errors), preserving existing APIs and UX for non-AI clients.
  • Cons:

    • Conversion quality dependency: Default League driver may struggle with complex HTML (e.g., JavaScript-rendered content, dynamic classes). Cloudflare driver mitigates this but introduces external dependencies.
    • Cache invalidation complexity: Shared cache store (e.g., Redis) could lead to stale markdown if not scoped properly (e.g., markdown-response: prefix recommended).
    • Attribute-based routing: While flexible, mixing middleware and attributes may complicate debugging for teams unfamiliar with Laravel’s attribute system.

Integration Feasibility

  • Low-risk for greenfield projects: Drop-in middleware + facade usage requires ~10–30 minutes to implement for basic use cases.
  • Brownfield challenges:
    • Legacy HTML: Poorly structured HTML (e.g., inline styles, non-semantic markup) may yield suboptimal markdown. Preprocessing (e.g., Blade @prepend directives) or custom drivers may be needed.
    • Dynamic content: Pages with heavy JavaScript (e.g., SPAs, real-time updates) may need server-side rendering (SSR) or Cloudflare Workers AI for accurate conversion.
    • Caching conflicts: Shared cache stores (e.g., Memcached) could bloat memory if markdown responses aren’t namespaced or TTLs aren’t optimized.

Technical Risk

Risk Area Severity Mitigation
Conversion accuracy Medium Start with League driver; switch to Cloudflare for complex pages.
Cache stampedes Low Use dedicated cache store (e.g., markdown-response) or aggressive TTLs.
Performance regression Low Benchmark with MARKDOWN_RESPONSE_CACHE_ENABLED=false to isolate overhead.
Attribute routing bugs Medium Test edge cases (e.g., method-level attributes overriding class-level).
Cloudflare dependency High Only enable if using Cloudflare; fallback to League driver in tests.
Testing complexity Low Leverage Markdown::fake() for unit tests; mock cache in integration tests.

Key Questions

  1. Content Strategy:
    • What percentage of routes require markdown conversion? (Prioritize high-traffic/AI-targeted pages.)
    • Are there pages with dynamic or JavaScript-rendered content? (Cloudflare driver may be necessary.)
  2. Infrastructure:
    • Is Cloudflare Workers AI feasible? (Cost, latency, and account setup overhead.)
    • What cache backend is used? (Dedicated store recommended for shared environments.)
  3. Team Skills:
    • Familiarity with Laravel middleware/attributes? (Training may be needed for attribute-based routing.)
    • Experience with HTML-to-markdown quirks? (Preprocessing may be required for legacy templates.)
  4. Monitoring:
    • How will conversion success/failure be tracked? (Log middleware execution or add health checks.)
    • What’s the acceptable markdown quality threshold? (A/B test with AI agents if possible.)

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Middleware: Native integration with Laravel’s middleware stack (e.g., ProvideMarkdownResponse).
    • Facades: Markdown facade for direct conversion (e.g., in jobs, commands).
    • Testing: Built-in testing utilities (Markdown::fake()) align with Laravel’s Pest/PHPUnit support.
    • Caching: Works with any Laravel cache store (Redis, database, etc.).
  • Non-Laravel Considerations:
    • PHP Version: Requires PHP 8.1+ (check compatibility with legacy apps).
    • Cloudflare: Only relevant if using Cloudflare Workers AI (otherwise, League driver is self-contained).
    • Alternative Frameworks: Not directly applicable to non-Laravel apps (e.g., Symfony, WordPress).

Migration Path

  1. Phase 1: Pilot Routes (Low Risk)

    • Apply middleware to 1–2 non-critical routes (e.g., /docs, /blog).
    • Verify conversion quality manually and via AI agent testing (e.g., curl with Accept: text/markdown).
    • Measure performance impact (response time, cache hit rate).
  2. Phase 2: Global Rollout (Medium Risk)

    • Apply middleware globally via bootstrap/app.php.
    • Exclude sensitive routes (e.g., /dashboard, /api/*) using DoNotProvideMarkdownResponse.
    • Configure caching (dedicated store + 1-hour TTL).
  3. Phase 3: Optimization (High Value)

    • Switch to Cloudflare driver for complex pages (e.g., /products with JS rendering).
    • Customize cache keys or TTLs based on traffic patterns.
    • Add monitoring for conversion errors (e.g., failed Cloudflare requests).

Compatibility

Component Compatibility Notes
Laravel Version 9.x, 10.x, 11.x Test with your specific version (e.g., 10.30+ for attribute support).
PHP Version 8.1+ Check for deprecated functions if using PHP < 8.1.
Cache Stores Any Laravel-supported store (Redis, database, etc.) Dedicated store recommended for shared environments.
HTML Structure Semantic HTML preferred; inline styles/JS may reduce quality. Preprocess templates if needed (e.g., remove style attributes).
AI User Agents Supports known bots (GPTBot, ClaudeBot); customizable via ai_user_agents config. Update config if new AI bots emerge.
Testing Frameworks Pest, PHPUnit Markdown::fake() works with both.

Sequencing

  1. Pre-requisites:

    • Ensure Laravel app is up-to-date (composer update).
    • Configure cache store (if not already set up).
    • Set up Cloudflare credentials (if using Cloudflare driver).
  2. Core Implementation:

    • Install package: composer require spatie/laravel-markdown-response.
    • Publish config: php artisan vendor:publish --tag="markdown-response-config".
    • Apply middleware to pilot routes.
  3. Testing:

    • Unit tests: Use Markdown::fake() to verify conversions.
    • Integration tests: Test .md URLs, Accept headers, and AI user agents.
    • Load testing: Simulate AI traffic to validate cache performance.
  4. Post-Launch:

    • Monitor conversion errors (e.g., Cloudflare API failures).
    • Adjust TTLs based on cache hit/miss ratios.
    • Iterate on excluded routes (e.g., add #[DoNotProvideMarkdown] to sensitive endpoints).

Operational Impact

Maintenance

  • Proactive Tasks:
    • Cache Management: Clear markdown cache during deployments if using shared stores (php artisan markdown-response:clear).
    • Driver Updates: Monitor League/Cloudflare driver updates for breaking changes (e.g., API deprecations).
    • AI User Agent List: Update ai_user_agents config if new bots emerge (e.g., SerperBot).
  • Reactive Tasks:
    • Conversion Failures: Log errors for failed conversions (e.g., malformed HTML, Cloudflare API limits).
    • Quality Degradation: Audit markdown output if AI feedback suggests poor quality (e.g., missing content).

Support

  • Troubleshooting:
    • No Markdown Returned: Verify middleware is applied, Accept header is set, or URL ends with .md.
    • Cache Issues: Check cache store configuration and TTL settings.
    • Cloudflare Errors: Validate API tokens and account IDs; monitor usage limits.
  • Documentation:
    • Update internal runbooks with:
      • How to test markdown responses (curl -H "Accept: text/markdown" http://app.com/about).
      • Cache invalidation procedures.
      • Driver-specific troubleshooting (e.g., League vs. Cloudflare).
  • Team Training:
    • Developers: Attribute-based routing (#[ProvideMarkdown]) and facade usage (Markdown::convert()).
    • QA: Testing with
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