Laravel: Adding Markdown Easily
Michelf/Markdown
I added markdown to one of my laravel sites the other day. Worked like a charm. In fact, as I explored in Smart Pills - Laravel, my initial struggles with learning a new PHP framework made me appreciate the seamless integration of Michelf/Markdown.
but
I went to add it to my next site… Related to what I discussed in Smart Pills - Laravel, I was initially excited about using markdown, but I encountered some issues that needed to be resolved. 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). The end result of adding Markdown support was a big relief, much like when I finally got Vue.js working smoothly on my site after some initial struggles - as I wrote about in I like the Vue from Here.
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.