phphtmllaravelmarkdownparsedown

Laravel 5 Parsedown returning plain html tags to browser


I've installed parsedown (am using laravel 5) for parsing markdown and when I run it it is changing the markdown to html but the browser is plainly showing the parsed markdown instead of applying those particular styles for example when I run the following

{{Parsedown::instance()->text('Hello _Parsedown_!')}}

I expect when I run it in the browser: Hello Parsedown!

but instead am getting the following: <p>Hello <em>Parsedown</em>!</p> and when I view the browsers page source I get the following &lt;p&gt;Hello &lt;em&gt;Parsedown&lt;/em&gt;!&lt;/p&gt; What could be the problem?


Solution

  • In laravel 5 or 5.x the {{ }} will parse the HTML to html entities. To escape the HTML blade has provided the way which is {!! !!}. This will print html instead of html entities.

    So your answer will be as below

    {!! Parsedown::instance()->text('Hello _Parsedown_!') !!}
    

    See the Reference ( Below ) taken from laravel official site.

    Displaying Unescaped Data

    By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:

    Hello, {!! $name !!}.