Blade Component to Render Markdown in Laravel

Packages

July 15th, 2021

laravel-markdown-featured.png

Laravel Markdown is a highly configurable markdown renderer and Blade component for Laravel by the folks at Spatie:

The package features a blade component that can render Markdown in blade templates, for example:

1<x-markdown>
2# My title
3
4This is a [link to our website](https://spatie.be)
5
6```php
7echo 'Hello world';
8```
9</x-markdown>

Would be converted to the following HTML:

1<div>
2 <h1 id="my-title">My title</h1>
3 <p>This is a <a href="https://spatie.be">link to our website</a></p>
4 <pre class="shiki" style="background-color: #fff"><code><span class="line"><span
5 style="color: #005CC5">echo</span><span style="color: #24292E"> </span><span style="color: #032F62">&#39;Hello world&#39;</span><span
6 style="color: #24292E">;</span></span>
7<span class="line"></span></code></pre>
8</div>

In addition to rendering markdown, this package helps you set up syntax highlighting (using Shiki via Shiki PHP) and is highly configurable. Some interesting configuration options include automatically adding anchor links to headers, toggling code highlighting, and configuring the theme used for syntax highlighting.

Check out the markdown.php configuration file for further details on all the configuration options available for this package.

You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.