marcandreappel/bladedown

Blade directives for Markdown parsing in Laravel 7+.

1.0.1 2020-06-23 00:48 UTC

This package is auto-updated.

Last update: 2024-04-23 08:48:47 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

License

See the LICENSE file.