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
Markdown Extra

Markdown Extra Laravel Package

twig/markdown-extra

Twig extension adding Markdown support: convert Markdown to HTML with the markdown_to_html filter, and convert HTML back to Markdown with html_to_markdown. Ideal for rendering user content and round-tripping between formats in Twig templates.

View on GitHub
Deep Wiki
Context7

A Twig extension for Markdown

Frequently asked questions about Markdown Extra
How do I integrate twig/markdown-extra into a Laravel 10/11 app using the Twig bridge?
Install via Composer (`composer require twig/markdown-extra`), then register the extension in your `config/twig.php` under the `extensions` array. No additional setup is needed—Laravel’s Twig bridge handles the rest. For Laravel 9, verify Twig 2.x compatibility or use a polyfill.
Does this package support auto-escaping for security in user-generated Markdown (e.g., comments, forums)?
Yes. The package includes a CVE-2026-46637 fix for auto-escaping untrusted Markdown input, reducing XSS risks. Use `{{ user_input|markdown_to_html }}` in Twig templates—no manual `e()` filters are required. Always keep the package updated to patch future vulnerabilities.
Can I use this for round-tripping between HTML and Markdown in Laravel (e.g., migrating legacy content)?
Absolutely. The `html_to_markdown` filter converts HTML back to Markdown, ideal for migrations or workflows like CMS content editing. Test with complex HTML (e.g., nested tags) to ensure compatibility, and cache results for performance in high-traffic apps.
What Laravel versions officially support twig/markdown-extra, and are there compatibility quirks?
Laravel 10/11 work seamlessly with Twig 3.x. Laravel 9 may need Twig 2.x validation or a polyfill due to Symfony 6.4+ deprecations. For Blade-only apps, wrap the package in a custom helper class to mimic Twig filters. Always check the [README](https://github.com/twigphp/markdown-extra) for updates.
How do I extend the Markdown syntax for domain-specific needs (e.g., LaTeX, custom shortcodes)?
Leverage Twig’s filter architecture to create custom filters. For example, extend `markdown_to_html` with a pre-processor hook to handle LaTeX or shortcodes before parsing. Document your extensions clearly for team adoption, and test thoroughly to avoid breaking changes.
Is there a performance impact when rendering Markdown in high-traffic Laravel endpoints?
Benchmark tests show <5% latency increase for Markdown rendering. Mitigate overhead by caching outputs with Laravel’s `Cache::remember()` or queueing heavy processing. For real-time apps (e.g., Livewire), prioritize caching or use lightweight Markdown subsets.
What alternatives exist for Markdown in Laravel, and why choose twig/markdown-extra?
Alternatives include `parsedown/parsedown` or `michelf/php-markdown`, but they lack Twig integration and bidirectional conversion. This package is Twig-native, offering seamless Laravel integration, auto-escaping for security, and extensibility. It’s ideal for apps using Twig (e.g., CMS, docs) or needing round-tripping.
How do I test for XSS vulnerabilities when using markdown_to_html in Laravel?
Inject test payloads like `<script>alert(1)</script>` into Markdown input and verify the output escapes HTML. Use Laravel’s `Html::entities()` for manual checks or integrate tools like `laravel-shift/security-checker`. Always test edge cases like nested tags or legacy HTML-in-Markdown content.
Can I use this package with Laravel Livewire for real-time Markdown editing (e.g., rich-text editors)?
Yes. The bidirectional filters work well with Livewire for real-time previews or round-tripping. Cache rendered outputs to reduce latency, and use Alpine.js or Tailwind CSS for UI feedback. For complex editors, consider pairing with a frontend library like `easymde` for client-side Markdown.
What’s the migration path if I’m replacing an existing Markdown parser (e.g., Parsedown) in Laravel?
Update Composer (`twig/markdown-extra:^3.26.0`), replace `{{ markdown }}` with `{{ input|markdown_to_html }}`, and use `html_to_markdown` for reverse workflows. Audit templates for hardcoded HTML or custom escaping logic. Phase the rollout starting with non-critical paths (e.g., documentation) before UGC-heavy routes.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata