Writing markdown inside blade
Hi, I'd like to do the following: write markDown in a blade template, so that I can write a long article easily and I don't have to add html tags myself. The idea is to then wrap that into a Tailwind prose class, and voila, I can easily write long articles as a pure blade template.
I haven't been able to make this work. Laravel seems to have markdown built it. The Spatie plugin isn't working for me, it renders a simple line of text as for some reason.
Any tips on how to achieve this? Seems like it would be really handy?
For people searching for this, this worked (with tweak). Here are the docs https://laravel.com/docs/10.x/blade#extending-blade
To AppServiceProvider, I added:
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;
and then in the boot() method of that page, I added
Blade::directive('markdown', function () {
return "Hello <?php echo(Str::markdown(<<<HEREDOC";
});
Blade::directive('endmarkdown', function () {
return "HEREDOC)); ?>";
});
(Note the double bracket at the end).
Now in the blade template, I can do:
@markdown
# A first-level heading
## A second-level heading
### A third-level heading
- bullet
- bullet
@endmarkdown
Finally, and this can be tricky, you have to clear the views because you just edited Blade. After you do that, it should work.
php artisan view:clear
Please or to participate in this conversation.