phpiframeyoutuber-markdownparsedown

SimpleMDE - Markdown embeding videos from Youtube


I 'm using SmpleMDE as my WYSIWYG editor and the Parsedown library for parsing the markdown and converting it into HTML.

<?php echo $this->parsedown->text($post->content); ?>

Everything works fine, the only problem is that I want to show up youtube videos within the content by adding the embeded <iframe>.

According to this answer Youtube video and text side by side in Markdown I can simply add the youtube <iframe> straight to my content, however the output shows the html code escaped

<p>&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;<a href="https://www.youtube.com/embed/7GqClqvlObY">https://www.youtube.com/embed/7GqClqvlObY</a>&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;</p>

The content in the database is stored like this

Lorem ipsum .....

&lt;iframe width="560" height="315" src="https://www.youtube.com/embed/7GqClqvlObY" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;


Lorem ipsum .....

How can I fix this so that the embeded code from youtube would show up properly?


Solution

  • Since the problem is that the strings are stored escaped in the database, try this:

    <?php echo $this->parsedown->text(htmlspecialchars_decode($post->content); ?>
    

    Also, take a look at the manual, you might have to add a flag depending on how your strings are encoded/escaped.