Blade Component to Render Markdown in Laravel
Published on by Paul Redmond
Laravel Markdown is a highly configurable markdown renderer and Blade component for Laravel by the folks at Spatie:
🚀 Using our newly released laravel-markdown package, you can easily render markdown to HTML. https://t.co/LdQL57c5Gg
— Freek Van der Herten 🔭 (@freekmurze) July 13, 2021
Code snippets in your markdown will be perfectly highlighted by Shiki (PHP, Blade, JS, …), which is also used by VSCode
Blogpost: https://t.co/1ntOapiiUw pic.twitter.com/uEsAA5BMjT
The package features a blade component that can render Markdown in blade templates, for example:
<x-markdown># My title This is a [link to our website](https://spatie.be) ```phpecho 'Hello world';```</x-markdown>
Would be converted to the following HTML:
<div> <h1 id="my-title">My title</h1> <p>This is a <a href="https://spatie.be">link to our website</a></p> <pre class="shiki" style="background-color: #fff"><code><span class="line"><span style="color: #005CC5">echo</span><span style="color: #24292E"> </span><span style="color: #032F62">'Hello world'</span><span style="color: #24292E">;</span></span><span class="line"></span></code></pre></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.