- How do I enable markdown responses for specific routes in Laravel?
- Use the `ProvideMarkdownResponse` middleware in your route group. For example, wrap routes like `Route::middleware(ProvideMarkdownResponse::class)->group(...)` to serve markdown when detected via headers, user agents, or `.md` suffixes.
- Does this package work with Laravel 10+ and PHP 8.1+?
- Yes, the package is fully compatible with Laravel 10+ and PHP 8.1+. It leverages modern Laravel features and avoids deprecated methods, ensuring smooth integration.
- Can I customize how HTML is converted to markdown?
- Yes, you can extend the conversion process by creating custom processors. The package supports hooks for preprocessing HTML or post-processing markdown, allowing you to handle edge cases like custom elements or diagrams.
- What happens if the markdown conversion fails?
- The package defaults to returning the original HTML if conversion fails. You can also configure fallback behavior in middleware or custom processors to handle malformed HTML gracefully.
- How does caching work with this package?
- The package includes built-in caching for markdown responses. Use Laravel’s cache system (e.g., `Cache::remember`) to store converted markdown, reducing repeated processing overhead for the same requests.
- Is there a way to test markdown responses before deploying?
- Yes, you can manually trigger conversions using the `Markdown::convert($html)` facade for unit testing. Additionally, test with AI agents/bots by sending requests with `Accept: text/markdown` headers or `.md` URLs.
- Does this package support Cloudflare Workers for conversion?
- Yes, the package supports driver-based conversion, including Cloudflare Workers AI. Configure the driver in your `.env` or service provider to switch between local PHP or Cloudflare for processing.
- Will this break existing HTML responses for non-markdown requests?
- No, the package only intercepts requests matching markdown detection criteria (headers, user agents, or `.md` paths). All other requests return the original HTML response unchanged.
- Are there any known compatibility issues with `spatie/laravel-responsecache`?
- The package integrates well with `spatie/laravel-responsecache`, but ensure you test caching behavior if using both. Refer to the docs for any quirks, as recent PRs (like #6) may address integration specifics.
- How do I handle unsupported HTML elements (e.g., `<canvas>`) in markdown?
- Unsupported elements default to `[unsupported]` in markdown. For custom handling, create a processor to replace or skip these elements before conversion, or use HTML preprocessing tools like TidyHTML.