Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Harrk/laravel-commonmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Commonmark

Build Status

Laravel Commonmark is a wrapper for league/commonmark which allows for the parsing of regular Markdown as well as CommonMark. The CommonMark spec can be found at http://commonmark.org.

This package can parse Markdown inline or within blade templates using the .md.blade.php file extension.

Why?

I was looking for a Markdown compiler for Laravel and with being unable to find a package compatible with Laravel 5.6 (at the time). I figured I could take a crack at it. This also seemed like a good opportunity to gain some experience with open-source projects.

Installation

This package has been updated to work with Laravel 6.0, just install via composer:

$ composer require "harrk/laravel-commonmark=~v2.0"

Usage

Blade

Simply name a blade view with the .md.blade.php extension and it'll automatically parse Markdown within the view into HTML when rendered.

Any .md.blade.php files can be included into other blade files using @import as you would a regular view.

Dependency Injection

use \League\CommonMark\CommonMarkConverter;

class MyClass {

    public function myFunction(CommonMarkConverter $converter) {
        return $converter->convertToHtml('# H1 Header');
    }
    
}

Or if you prefer using helper functions instead:

class MyClass {

    public function myFunction() {
        return markdown_to_html('# H1 Header');
    }
    
}

Unit Testing

To run unit tests:

$ vendor/bin/phpunit

Alternatives

Check out graham-campbell/markdown for a package that offers far greater customisation through the use of CommonMark extensions.

About

A Markdown parser for Laravel

Resources

Stars

Watchers

Forks

Packages

No packages published