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.
twig/laravel). It leverages Laravel’s service provider architecture for seamless integration, requiring minimal boilerplate. The bidirectional Markdown/HTML conversion aligns with Laravel’s content-heavy use cases (e.g., CMS, forums, documentation systems).e() filters in Blade), streamlining security.markdown_to_html hooks). This is valuable for domain-specific languages (DSLs) or scientific/technical documentation platforms.twig/laravel (Twig 3.x). No additional configuration required beyond registering the extension in config/twig.php.MarkdownHelper).parsedown/parsedown, michelf/php-markdown) with twig/markdown-extra:^3.26.0.{{ user_input|e }}) with {{ user_input|markdown_to_html }}. Use html_to_markdown for reverse workflows (e.g., HTML-to-Markdown migrations).<script> tags; output should escape)./comments, /wiki) first.{{ input|markdown_to_html(escape: false) }}). Solution: Add a Laravel validation rule (e.g., ValidMarkdown) to reject unescaped content.<iframe> tags). Solution: Implement a whitelist mechanism for trusted HTML blocks.twig/twig:^2.15 or use a compatibility layer.Cache::remember()).markdown-extra recipe in the Laravel Wiki).twig/laravel, requiring only a service provider registration:
// config/twig.php
'extensions' => [
Twig\MarkdownExtraExtension::class,
],
// app/Helpers/MarkdownHelper.php
function markdown($content) {
return app('twig')->getExtension('markdown_extra')->markdownToHtml($content);
}
symfony/markdown:^6.4, ensuring compatibility with Laravel’s modern PHP stack (PHP 8.1+).composer require twig/markdown-extra.storage/framework/cache/ (e.g., for blog posts).parsedown/parsedown) for redundancy.composer require twig/markdown-extra:^3.26.0 --update-with-dependencies
{{ user_comment|e }} {# Old: Manual escaping #}
With:
{{ user_comment|markdown_to_html }} {# New: Auto-escaping #}
{{ legacy_html|html_to_markdown }}
use Illuminate\Validation\Rule;
Rule::markdownSafe(function ($attribute, $value, $fail) {
if (str_contains($value, '<script>')) {
$fail('Markdown contains unsafe HTML.');
}
});
| Laravel Version | Twig Version | Compatibility Notes |
|---|---|---|
| 10.x/11.x | 3.x | Full support. |
| 9.x | 2.x | Test with twig/twig:^2.15. |
| <9.x | 1.x | Not recommended (deprecated Twig 1.x). |
/api/docs).How can I help you explore Laravel packages today?