- How do I install Parsedown Extra in a Laravel project?
- Run `composer require erusev/parsedown-extra` to install the package. It depends on `erusev/parsedown`, which will auto-install. No additional Laravel-specific setup is required unless you want to bind it as a singleton or create a facade.
- Does Parsedown Extra support Laravel Blade templates?
- Yes, you can integrate it with Blade by creating a custom directive like `@markdown` or binding it as a service provider. This lets you render Markdown directly in views without extra logic.
- What Laravel versions does this package support?
- Parsedown Extra works with Laravel 9+ (PHP 8.0+) since it depends on Parsedown 2.0+. It’s fully compatible with Laravel’s latest LTS releases and avoids version conflicts.
- Can I use this for user-generated content like forum posts or comments?
- Yes, but sanitize the output to prevent XSS. Parsedown Extra converts Markdown to HTML, so always escape or whitelist allowed tags if users can input raw Markdown.
- How do I extend Parsedown Extra for custom syntax (e.g., shortcodes)?
- Use Parsedown’s extension system. Create a custom extension class and register it with `ParsedownExtra::addExtension()`. This lets you add features like shortcodes, custom block types, or GitHub-flavored tables.
- Is Parsedown Extra faster than other Markdown parsers like CommonMark?
- Yes, it’s optimized for speed with a lightweight footprint (~10KB). It’s ideal for high-traffic Laravel apps where performance matters, especially if you only need Markdown Extra features.
- How do I cache parsed Markdown to avoid reprocessing on every request?
- Use Laravel’s cache drivers with `Cache::remember()`. Store the parsed HTML for a key like `markdown:{$contentHash}` and set a TTL (e.g., 1 hour) for dynamic content.
- What happens if a user submits malformed Markdown (e.g., broken tables)?
- Parsedown Extra gracefully handles malformed input by outputting raw HTML or skipping invalid blocks. Test edge cases in your app to ensure robustness, especially for public-facing content.
- Can I use this package in API responses to return HTML from Markdown fields?
- Absolutely. Inject the parser as a service and use it in controllers to convert Markdown fields (e.g., `Post::content`) to HTML before returning JSON or rendering views.
- What are the alternatives to Parsedown Extra in Laravel?
- Alternatives include `spatie/laravel-markdown` (wraps Parsedown), `league/commonmark` (full CommonMark support), or `michelf/php-markdown` (older but feature-rich). Parsedown Extra is lighter and focuses on Markdown Extra syntax.