LesPerras.com

Laravel: Adding Markdown Easily

Michelf/Markdown

I added markdown to one of my laravel sites the other day. Worked like a charm. I used Michelf/Markdown and had no problems.

but

I went to add it to my next site… I love markdown… but there were problems. I added it to composer.json first. Just add "michelf/php-markdown": "1.4.1" to your composer.json and then install or update composer. Now for the but. It didn’t work. I used the

@markdown()

syntax in my blade template, but nogo.

So

after a bit of searching I finally found the code that I was missing…

add this:

Blade::extend(function($view, $compiler){$pattern = $compiler->createMatcher('markdown'); $replace = '<?php echo \Michelf\Markdown::defaultTransform$2; ?>'; return preg_replace($pattern, $replace, $view); });

to your

/app/start/global.php

(just stick it on the end of the file is ok). Then Presto! It works!

And to use it:

// usage, in a blade template: // @markdown( $some->property ) // @markdown('some string *with style*')