Now You Can Do More with Laravel Mails Using Custom Markdown Extensions

Last updated on by Dasun Tharanga

1 min read

We recently wanted to extend Markdown support for mails at Jacasa for our ongoing project.

That led me to open this PR to Laravel: laravel/framework#59051

It was merged by Taylor Otwell, and now we can register CommonMark extensions directly for mail rendering.

For example, you can enable StrikethroughExtension in your mail markdown config:

'markdown' => [
'theme' => 'default',
'paths' => [resource_path('views/vendor/mail')],
'extensions' => [
\League\CommonMark\Extension\Strikethrough\StrikethroughExtension::class,
],
],

Then use it in your mail Blade template like this:

<x-mail::message>
~~This line is struck through~~
</x-mail::message>

You can also create your own custom CommonMark extension and register it in the same extensions array:

'extensions' => [
\App\Mail\Markdown\CustomExtension::class,
],

A small change, but a useful one: Laravel mails now give us a cleaner path to richer Markdown formatting.