- How do I install Parsedown Extra in a Laravel project?
- Run `composer require erusev/parsedown-extra` to install the package. It requires PHP 8.0+ and automatically pulls in the base Parsedown library. No additional Laravel-specific setup is needed unless you want to integrate it globally via a service provider.
- Does this package support all Markdown Extra features like tables and fenced code blocks?
- Yes, Parsedown Extra fully supports Markdown Extra extensions, including tables, footnotes, definition lists, and fenced code blocks. It’s built on top of Parsedown to ensure compatibility with these advanced syntaxes while keeping the output clean and predictable.
- Can I use this in Laravel Blade templates?
- Absolutely. You can register a Blade directive (e.g., `@markdown`) or use a facade to render Markdown directly in views. For example, create a `Markdown` facade pointing to the ParsedownExtra instance, then use `{{ markdown($content) }}` in your Blade files.
- Is Parsedown Extra compatible with Laravel 10+?
- Yes, the package supports PHP 8.0+, which aligns with Laravel’s LTS versions (including Laravel 10). It’s framework-agnostic but integrates seamlessly with Laravel’s dependency injection and service container.
- How do I handle user-generated Markdown safely to avoid XSS?
- Parsedown Extra outputs sanitized HTML by default, but for extra security, use Laravel’s `Str::of()` or `htmlspecialchars()` on the parsed output if the input is untrusted. Alternatively, integrate a package like `spatie/laravel-html` for stricter sanitization.
- What’s the performance impact of using this in a high-traffic Laravel app?
- Parsedown Extra is optimized for speed, with minimal overhead (~10KB). For high-traffic apps, cache the parsed HTML (e.g., using Laravel’s cache drivers) to avoid reprocessing Markdown on every request. Benchmark with your specific use case for exact metrics.
- Can I extend Parsedown Extra with custom syntax (e.g., shortcodes)?
- Yes, the package leverages Parsedown’s extension system. You can add custom syntax by creating a subclass of `ParsedownExtra` and registering your extensions via `setBreaksEnabled()`, `setMarkupEscaped()`, or by implementing custom `BlockParser`/`InlineParser` classes.
- What’s the fallback strategy if Parsedown Extra fails in production?
- If you need a fallback, instantiate a basic `Parsedown` instance (from `erusev/parsedown`) as a secondary parser. Wrap the primary Parsedown Extra logic in a try-catch block and return the fallback output if an exception occurs.
- Does this package work with Laravel’s API responses?
- Yes, you can use Parsedown Extra in API controllers to convert Markdown fields (e.g., `Post::content`) to HTML before returning JSON responses. Example: `return response()->json(['content' => Markdown::text($post->content)]);`.
- Are there alternatives to Parsedown Extra for Laravel Markdown parsing?
- Alternatives include `spatie/laravel-markdown` (which wraps Parsedown) or `league/commonmark` for CommonMark support. Parsedown Extra is lighter and more focused on Markdown Extra features, making it ideal for apps needing tables, footnotes, and definition lists without extra dependencies.