Back to ProBlog Support

paulgrafx
paulgrafx

I am trying to add code syntax content to my blog posts using markup. See example below. I have had to replace ``` with ''' to make it viewable.

'''php <?php echo 'hello world'; ?> '''

This works fine until I go back to edit the content and it replaces it with.

<pre><code class="language-php"><?php
echo 'hello world';
?></code></pre>

Therefore it stops working.

It seems the column 'content_markdown' gets translated to pure html somehow before it gets to the rich text editor.

Last updated

paulgrafx
paulgrafx

TEMP FIX.

I have found a fix for the issue above but unsure if it will affect anywhere else.

I have noted out the following function in the file radiantweb/problog/model/Post.php

public function afterFetch() {
....
}

Markdown appears correctly when going back to edit the post. The code snippet also appears correctly on the front end.

UPDATE: This only works if the markdown is already set/copied in the other database column otherwise it will bring back empty content!

Last updated

paulgrafx
paulgrafx

Solved the issue using the following...

problog/models/post.php
use App;

public function afterFetch()
{

  if (App::runningInBackend()) {

    if (ProblogSettingsModel::get('markdownMode', true) {
      $this->content_markdown = htmlspecialchars($this->content_mardown, ENT_QUOTES);
    }

  }

}
Example special characters such as '&#58;' needs to be saved as '&#38;#58;' when outputting code syntax in content.

Last updated

paulgrafx
paulgrafx

Update - I found an easier way to sort this issue without editing the problog plugin, by adding a custom extended plugin.

public function boot()
{
$model->bindEvent('model.afterFetch', function() use ($model) {     
    if (App::runningInBackend()) {          
        if (ProblogSettingsModel::get('markdownMode', true)) {
            $model->content = htmlspecialchars($model->content_markdown, ENT_QUOTES);
        }
    }
});
}

1-4 of 4