I see there is a Markdown class CMarkdown
, but how do I use it?
There's no examples anywhere and the methods aren't self explanatory.
Do I use it statically like CHtml
, or weird like a Widget?
Or do I have to init
it somewhere like a Model?
You can use CMarkdown as a widget in a view like this:
$this->beginWidget('CMarkdown', array('purifyOutput'=>true));
echo $content;
$this->endWidget();
When the $content contains Markdown syntax it will be processed by the widget. The array contains values for the public properties of CMarkdown. The properties are documented in the class reference.
CMarkdown is used in the Yii blog example and you will find it in this view file.
This works and is imo the easiest:
static function markdown( $str ) {
$md = new CMarkdown;
return $md->transform($str);
}
A static function in the parent Controller. Probably not the Yii way, but it's simple:
<?=self::markdown($post->body)?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With