Giter Site home page Giter Site logo

alfredoramos / parsedown-extra-laravel Goto Github PK

View Code? Open in Web Editor NEW
26.0 4.0 0.0 186 KB

A Parsedown Extra package for Laravel and Lumen

License: GNU General Public License v3.0

PHP 100.00%
markdown markdown-extra parsedown parsedown-extra laravel lumen

parsedown-extra-laravel's Introduction

About

A Parsedown Extra package for Laravel and Lumen.

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.

Build Status Latest Stable Version Code Quality License

Compatibility

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 Security fixes only
5.x.x 10.x.x 10.x.x Active support

Installation

Open your composer.json file and add the package in the require object:

"alfredo-ramos/parsedown-extra-laravel": "^5.0.0"

Then run composer update on your terminal.

Laravel

Service providers and aliases will be registered automatically since Laravel 5.5.x, thanks to the new package auto-discovery.

Lumen

In your bootstrap\app.php file and register the service provider:

$app->register(AlfredoRamos\ParsedownExtra\ParsedownExtraServiceProvider::class);

Then register the facade alias:

$app->withFacades(true, [
	AlfredoRamos\ParsedownExtra\Facades\ParsedownExtra::class => 'Markdown'
]);

Usage

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:

  • If $config is a string, it will be trated as an array key in the [purifier][settings] array.
  • If $config is an array it will extend default configuration for HTML Purifier.
  • An empty value for $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'])

Blade

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>

Helper

For your convenience, the markdown() helper function is also available. It accepts the same parameters as the facade.

markdown('Hello world', ['purifier' => false])

Configuration

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.