Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 201
user3714932 Avatar asked Jul 15 '15 18:07

user3714932


1 Answers

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 !!}.
like image 67
Pratik Soni Avatar answered Sep 20 '22 18:09

Pratik Soni