spatie / laravel-markdown
A highly configurable markdown renderer and Blade component for Laravel
Fund package maintenance!
spatie
Requires
- php: ^8.1
- illuminate/cache: ^9.0|^10.0|^11.0
- illuminate/contracts: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
- illuminate/view: ^9.0|^10.0|^11.0
- league/commonmark: ^2.6.0
- spatie/commonmark-shiki-highlighter: ^2.5
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- brianium/paratest: ^6.2
- nunomaduro/collision: ^5.3|^6.0
- orchestra/testbench: ^6.15|^7.0|^8.0
- pestphp/pest: ^1.22
- phpunit/phpunit: ^9.3
- spatie/laravel-ray: ^1.23
- spatie/pest-plugin-snapshots: ^1.1
- vimeo/psalm: ^4.8
README
This package contains:
- a Blade component that can render markdown
- a highly configurable class that you can use to render markdown
Let's start with an example of the provided x-markdown
Blade component. This chunk of markdown...
<x-markdown> # My title This is a [link to our website](https://spatie.be) ```php echo 'Hello world'; ``` </x-markdown>
... will be converted by to component to this chunk of 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>
You can also programmatically render HTML.
// by resolving the class out of the container all the options // in the config file will be used. app(Spatie\LaravelMarkdown\MarkdownRenderer::class)->toHtml($markdown);
Out of the box, the x-markdown
component and MarkdownRenderer
can:
- highlight code blocks correctly (via Shiki PHP) for 100+ languages, including PHP, JS, Blade, and many more.
- add anchor links to headings
- cache results to increase performance
Support us
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
Documentation
You can find installation instructions and detailed instructions on how to use this package at the dedicated documentation site.
Related packages
If you only need the league/commonmark extension to highlight code, head over to spatie/commonmark-shiki-highlighter.
In case you don't need the markdown support, but want to highlight code directly, take a look at spatie/shiki-php.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
Alternatives
If you don't want to install and handle Shiki yourself, take a look at Torchlight, which can highlight your code with minimal setup.
License
The MIT License (MIT). Please see License File for more information.