ingress-it-solutions / laravel-markdown-viewer
Simple Blade directive for markdown parsing.
Requires
- erusev/parsedown: ^1.6
- illuminate/support: >=7.0 < 11|^11
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-11-15 11:55:39 UTC
README
⚠️ Important
This project is no longer maintained, will not received any updates and will not support future versions of Laravel.
Laravel-Markdown-Viewer
A small, lightweight and easy-to-use Laravel package for handling markdown. It comes with a facade, a helper function and a Blade directive to make life easier for you.
Installation
To install it, simply pull it down with Composer. Run the php artisan vendor:publish
command to publish the configuration file.
composer require andreasindal/laravel-markdown:"3.0.1"
Laravel 5.5 and above use Package Auto-Discovery, so you do not have to manually add the MarkdownServiceProvider.
Usage
Blade-directive
The markdown parser may be used in your Blade templates by using the @markdown
directive.
<article> <h1>{{ $post->title }}</h1> <section class="content"> @markdown($post->body) </section> </article>
You can also use a block-style syntax:
@markdown # Hello world This *text* will be **parsed** to [HTML](http://laravel.com). @endmarkdown
Facade
If you registered the Markdown facade as shown above, you can easily parse markdown using it.
$markdown = "# Hello"; $html = Markdown::parse($markdown) // <h1>Hello</h1>
Helper-functions
$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>
Of course, you could also resolve the parser from the service container and use it yourself.
$parser = app('Ingress\Markdown\Parser'); $html = $parser->parse('# Hello'); // <h1>Hello</h1>
Drivers (NEW!)
Laravel-Markdown-Viewer allows you to add custom markdown drivers. In order to use a custom markdown driver, you need to create a class that implements the Ingress\Markdown\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.
Laravel-Markdown-Viewer ships with a ParsedownDriver
using the Parsedown-package by @erusev.
Copyright
Copyright by Ingress IT Solutions