Yii 1.1: yii-prettify

Syntax highlighting tool of source code snippets
6 followers

This widget enable syntax highlighting of code snippets in your web application using Google Code Prettify.

Requirements

Yii 1.1.6 or above...(tested with 1.1.10)

Usage

  • install and explore the demo application
  • or extract the widget file under .../protected/extensions
  • put in a view a code block like the following...

Sample : HTML code

<?php $this->beginWidget('ext.prettify.JPrettify');?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Code Sample</title>
  </head>
  <body>
    <b>Hello World!</b>
  </body>
</html>
<?php $this->endWidget();?>

Sample : PHP code from file

<?php
$this->widget('ext.prettify.JPrettify',array(
    'lang'=>"php5",
    'showLineNumbers'=>true,
    'pathAlias'=>"system.base",
    'fileName'=>"CComponent.php",
    'htmlOptions'=>array('style'=>'max-height: 340px; overflow-y: scroll;')
));
?>

Sample : HTML5 code from any website

<?php
$this->widget('ext.prettify.JPrettify',array(
    'fileName'=>"http://www.yiiframework.com/",
    'htmlOptions'=>array('style'=>'max-height: 600px; overflow-y: scroll;'))
);
?>

Change log

Version 1.0

  • initial release

Version 1.1

  • code cleaning
  • bug fix
  • better support for highlighting of PHP5 keywords

Resources

Google Code Prettify

Alternate Yii extension

Be the first person to leave a comment

Please to leave your comment.

Create extension