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*')
Get My Free E-book
Cleaner Living: Breathe through life's difficulties
Learn the scanning breath technique that helped me dissolve decades of emotional baggage. Discover practical tools you can use anywhere to process difficult emotions and find lasting well-being.
We respect your privacy. Your email will only be used to send the download link.