0

I am using the PHP League Commonmark package in a Laravel application. Commonmark's convertToHtml() is returning html wrapped in double quotes. This content is, of course, rendered on the page with the html tags displayed. I am using a presenter to convert the md that is returned from my DB. I have confirmed that there are no quotes in the content in the db.

I have used the package before, and cannot find what I am doing wrong. Can anyone point me in the right direction?

Here is my presenter (the extended class is the Laracasts presenter):

class ContentPresenter extends Presenter
{
private $markdown;

public function bodyHtml()
{
    $this->markdown = new CommonMarkConverter();

    return $this->body ? $this->markdown->convertToHtml($this->body) : null;
}

}
Roger Creasy
  • 1,419
  • 2
  • 19
  • 35
  • Your issue is probably not double quotes? as this should not be a problem. your issue is likely escaped quotes. just unescape the quotes. – jeremy Feb 05 '17 at 14:17
  • @jeremy I'm not sure what you mean. There are no quotes in the content. The content is: **Test Content** Which should give me

    – Roger Creasy Feb 05 '17 at 14:19
  • I don't understand the question then : double quotes will not prevent HTML from rendering. – jeremy Feb 05 '17 at 14:32
  • OK. Any idea what else would cause the html tags to display on the page? There is nothing odd on the page. The content is just rendered within a div. – Roger Creasy Feb 05 '17 at 14:39
  • 1
    Time for some `var_dump`'s to find where the double quotes are being introduced? i.e. `var_dump($this->body);`. And `var_dump($this->markdown->convertToHtml($this->body));` – Ryan Vincent Feb 05 '17 at 14:40
  • @RyanVincent thanks, I have the quotes in both spots. I tried using trim(), no luck. – Roger Creasy Feb 05 '17 at 19:45
  • I tried dumping the response from the db before the presenter - in the controller. Everything is wrapped in quotes. Is there perhaps something different in Laravel 5.4 that could cause this? Haven't had this problem with past versions... – Roger Creasy Feb 05 '17 at 19:54
  • I think I have been incorrect in assuming the quotes are the problem. The problem is that html tags are displayed on my rendered page. Apologies for my incorrect assumption. – Roger Creasy Feb 05 '17 at 19:58
  • HTML Tags being displayed are a possible indication of 'double escaping'... 'Presenter' and 'commonMark' being to eager to be safe? – Ryan Vincent Feb 05 '17 at 20:00
  • 1
    @RyanVincent That was it! Thanks! The problem was in my Blade template. – Roger Creasy Feb 05 '17 at 20:48

1 Answers1

2

I was using the incorrect bracket format in Blade templates. I was using {{ }}, which escapes content. I switched to {!! !!}, which does not escape the content.

See this SO answer for more: https://stackoverflow.com/a/35031303/4374801

Thanks to all above who helped tremendously in the comments.

Community
  • 1
  • 1
Roger Creasy
  • 1,419
  • 2
  • 19
  • 35