Yii code listing widget
I was wondering if the Yii framework already has a widget for pretty-printing source code on a web page. I mean with line num开发者_JAVA百科bers, alignment and perhaps some nice keyword coloring. Thanx :)
You need to use CTextHighlighter. The Yii playground has a good example demo of this working complete with source code here.
You could use a CMarkdown widget to pretty-print code. CMarkdown offers a lot of options to make blocks of text look good.
You can enable syntax highlight code with CMarkdown by placing your code in a block like this:
~~~
[code showLineNumbers=1]
Enter code here.
~~~
showLineNumbers=1 is optional and enables line numbering for the block.
code
should be one of ABAP, CPP, CSS, DIFF, DTD, HTML, JAVA, JAVASCRIPT, MYSQL, PERL, PHP, PYTHON, RUBY, SQL or XML.
Example:
~~~
[php showLineNumbers=1]
<?php
echo phpinfo();
?>
~~~
You can use CMarkdown in a view like this:
$this->beginWidget('CMarkdown', array('purifyOutput'=>true'));
echo $content;
$this->endWidget();
精彩评论