jeffersongoncalves / laravel-markdown
A shared CommonMark renderer for Laravel with GitHub Flavored Markdown, optional heading permalinks, and server-side syntax highlighting (class-based tokens) via tempest/highlight. Renders raw HTML for trusted-pipeline rendering — pair with jeffersongoncalves/laravel-html-sanitizer before displaying
Package info
github.com/jeffersongoncalves/laravel-markdown
pkg:composer/jeffersongoncalves/laravel-markdown
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/support: ^11.0|^12.0|^13.0
- league/commonmark: ^2.4
- spatie/laravel-package-tools: ^1.14
- tempest/highlight: ^2.25
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.7.4|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
This package is auto-updated.
Last update: 2026-06-20 21:26:22 UTC
README
Laravel Markdown
A shared CommonMark renderer for Laravel with GitHub Flavored Markdown, optional heading permalinks, and server-side syntax highlighting on fenced code blocks. Highlighting is class-based (<span class="hl-…"> tokens via tempest/highlight's CssTheme) so the markup survives HTML sanitisation — you style the .hl-* classes in your own CSS.
Installation
You can install the package via composer:
composer require jeffersongoncalves/laravel-markdown
You can publish the config file with:
php artisan vendor:publish --tag="markdown-config"
This is the contents of the published config file:
return [ 'html_input' => 'allow', 'allow_unsafe_links' => false, 'heading_permalink' => [ 'symbol' => '#', 'html_class' => 'md-anchor', ], ];
Usage
use JeffersonGoncalves\Markdown\Markdown; // Render GitHub Flavored Markdown to HTML $html = Markdown::render('# Hello **world**'); // Enable heading permalink anchors (adds <a class="md-anchor"> to each heading) $html = Markdown::render($readme, headingPermalinks: true);
Fenced code blocks are highlighted server-side and emit class-based tokens:
$html = Markdown::render(<<<'MD' ```php echo 'hello'; ``` MD); // => <pre><code>…<span class="hl-keyword">echo</span>…</code></pre>
Add the matching .hl-* styles (and .md-anchor if you use heading permalinks) to your own CSS.
Warning
The renderer runs with html_input set to allow, so the output is UNSAFE for untrusted input (third-party READMEs, imported article bodies): raw HTML in the source is preserved. Always pass the output through an HTML sanitizer such as jeffersongoncalves/laravel-html-sanitizer before displaying it. Class-based highlight tokens are designed to survive sanitisation; inline-style highlighting would not.
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
License
The MIT License (MIT). Please see License File for more information.
