ryangjchandler/commonmark-blade-block

Embed Laravel Blade code inside of your Markdown templates.

v1.0.0 2024-10-17 15:59 UTC

This package is auto-updated.

Last update: 2024-12-17 16:21:51 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides an extension for league/commonmark that lets you embed Laravel Blade code inside of your Markdown content.

Installation

You can install the package via Composer:

composer require ryangjchandler/commonmark-blade-block

Usage

Start by registering the extension.

use League\CommonMark\MarkdownConverter;
use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use RyanChandler\CommonmarkBladeBlock\BladeExtension;

$environment = new Environment();

$environment
    ->addExtension(new CommonMarkCoreExtension)
    ->addExtension(new BladeExtension);

$converter = new MarkdownConverter($environment);

Then start embedding Blade inside of your Markdown content with the @blade and @endblade tags.

# Hello, world!

@blade
<x-button>
    Click me!
</x-button>
@endblade

Using Laravel's Str or str() helpers

If you're using Str::markdown() or str()->markdown(), then you can register the extension through the extensions argument.

Str::markdown(
    <<<'MD'
    @blade
        <x-button></x-button>
    @endblade
    MD,
    extensions: [
        new BladeExtension(),
    ]
)

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.