Yii Blog Markdown Syntax Code Block Fix
A couple of days ago, I decided to write something on my blog based on Yii. By using Markdown syntax I was able to format my tutorials. However, the code block in my tutorial could not be displayed properly. If you have the same problem as mine, here’s a solution I figured out.
- Make sure you have the latest Yii v1.1.7.
- Make sure you insert a new line before your code block.
- Instead of using widget with CMarkdown, use CMarkdownParser.
In protected/views/post/_view.php replace the code:
<?php $this->beginWidget('CMarkdown', array('purifyOutput'=>false)); echo $data->content; $this->endWidget(); ?>
<?php $markdownParser = new CMarkdownParser; echo $markdownParser->safeTransform($data->content); ?>
Here’s an example html code block that works for me:
Hope that helps.