marcandreappel / bladedown
Blade directives for Markdown parsing in Laravel 7+.
Requires
- erusev/parsedown: ^1.6
- illuminate/support: ^7.0
Requires (Dev)
- nunomaduro/larastan: ^0.5.7
- orchestra/testbench: ^5.2
- sensiolabs/security-checker: ^6.0
- symplify/easy-coding-standard: ^7.3
Conflicts
This package is auto-updated.
Last update: 2024-11-23 10:00:15 UTC
README
A small and lightweight Laravel 7 package for parsing markdown inside of Blade templates.
Installation
Install it with Composer:
composer require marcandreappel/bladedown
Run the php artisan vendor:publish
command to publish the configuration file.
Usage
Blade directive
The markdown parser can be used in Blade templates by using the @markdown
directive:
<article>
<h1>{{ $post->title }}</h1>
<section class="content">
@markdown($post->body)
</section>
</article>
A block-style syntax is also available:
@markdown
# Hello world
This *text* will be **parsed** to [HTML](http://laravel.com).
@endmarkdown
Facade
$markdown = "# Hello";
$html = Markdown::parse($markdown); // <h1>Hello</h1>
Helpers
$html = markdown('# Hello'); // <h1>Hello</h1>
$html = markdown_capture(function () {
echo "# Hello";
echo "\n\n";
echo "So **cool**!";
});
// <h1>Hello</h1>
// <p>So <b>cool</b>!</p>
You can also resolve the parser from the service container:
$parser = app('Appel\Bladedown\Parser');
$html = $parser->parse('# Hello'); // <h1>Hello</h1>
Drivers
Bladedown allows you to add custom markdown drivers. In order to use a custom markdown driver, you need to create a class which implements the Appel\Bladedown\Drivers\MarkdownDriver
interface.
The interface contains two methods: text
and line
. text
is used to convert a block of markdown to HTML, while line
is used to convert a single line.
Bladedown ships with a ParsedownDriver
using the Parsedown library by @erusev.
Important notes
This package is incompatible with andreasindal/laravel-markdown
, because it is build upon it.
Credits
- Andreas Indal (@andreasindal)
- Mohamed Said (@themsaid)
- Emanuil Rusev (@erusev)
License
See the LICENSE file.