A Parsedown Extra package for Laravel
alfredo-ramos/parsedown-extra-laravel is a Laravel package for a parsedown extra package for laravel.
It currently has 27 GitHub stars and 155.477 downloads on Packagist (latest version 7.1.0).
Install it with composer require alfredo-ramos/parsedown-extra-laravel.
Discover more Laravel packages by alfredo-ramos
or browse all Laravel packages to compare alternatives.
Last updated
A Parsedown Extra package for Laravel.
HTML Purifier is also used to filter the HTML output, protecting your application for insecure content. Additionally, HTML5 Definitions for HTML Purifier is used to add new definitions and sanitization for HTML5.
| Version | Laravel | Lumen | Status | | :-----: | :---------------: | :---------------: | :------------: | | 0.8.x | >= 5.5.x, < 6.x.x | >= 5.5.x, < 6.x.x | End of life | | 1.x.x | 6.x.x | 6.x.x | End of life | | 2.x.x | 7.x.x | 7.x.x | End of life | | 3.x.x | 8.x.x | 8.x.x | End of life | | 4.x.x | 9.x.x | 9.x.x | End of life | | 5.x.x | 10.x.x | 10.x.x | End of life | | 6.x.x | 11.x.x | 11.x.x | Active support | | 7.x.x | 12.x.x | N/A | Active support |
Run the following command on your terminal:
composer require 'alfredo-ramos/parsedown-extra-laravel:^7.0.0'
Service providers and aliases will be registered automatically since Laravel 5.5.x, thanks to the new package auto-discovery.
Support for Lumen has been dropped since version 7.x.x. If you need this package for Lumen up to version 11.x.x, please install the previous major version 6.0.0
The Markdown::parse() method is responsible to transform the Markdown syntax into HTML, its signature is the following:
Markdown::parse(string $text = '', array $config = [])
| Parameter | Data type | Default value | Required | Description |
| :-------: | :---------------: | :-----------: | :------: | :------------------------------------ |
| $text | string | '' | Yes | Markdown text |
| $config | array, string | [] | No | Extra configuration for HTML Purifier |
Notes:
$config is a string, it will be trated as an array key in the ['purifier']['settings'] array.$config is an array it will extend default configuration for HTML Purifier.$config means that it will use default values for HTML Purifier, see \AlfredoRamos\ParsedownExtra\HTMLPurifierLaravel::getConfig() for more information.Using $config as a string
Markdown::parse('Hello world', ['config' => 'comments'])
Where comments is the key of the array settings.
return [
'purifier' => [
'enabled' => true,
'settings' => [
'default' => [...],
'comments' => [...]
]
]
];
Using $config as an array
Markdown::parse('[DuckDuckGo](https://duckduckgo.com/)', ['config' => [
'URI.Host' => 'localhost',
'URI.DisableExternal' => true
]])
For all configuration options see the official HTML Purifier config docs.
Using default settings
Markdown::parse('Hello world!')
// Is the same as
Markdown::parse('Hello world!', ['config' => 'default'])
It can be used in Blade through the Markdown facade:
{!! Markdown::parse("Hello world") !!}
{!! Markdown::parse("[XSS link](javascript:alert('xss'))") !!}
The code above will print:
<p>Hello world</p>
<!-- HTML Purifier enabled -->
<p><a>XSS link</a></p>
<!-- HTML Purifier disabled -->
<p><a href="javascript:alert('xss')">XSS link</a></p>
For your convenience, the markdown() helper function is also available. It accepts the same parameters as the facade.
markdown('Hello world', ['purifier' => false])
To add new or edit the default options, run the following command to make a copy of the default configuration file:
php artisan vendor:publish \
--provider='AlfredoRamos\ParsedownExtra\ParsedownExtraServiceProvider' \
--tag=config --force