Yii 1.1: geshi-highlighter

highlight code by GeSHi engine
5 followers

Using GeSHi highlight engine to highlight, to instead CTextHighlighter because it's poor language support.

Requirements

Yii 1.1 or above,
Other not tested.

Usage

put files into application.components;

Thanks for yiqing95's help :=) http://www.yiiframework.com/extension/geshi-highlighter/#c4321

when using like a COutputFilter, just like other filter.
for more detail, check here
and there's a example below

define an array in CController::filters like this

public function filters()
{
    return array(
        array('application.geshi.GeSHiHighlighter',
              'language' => 'html',
        ),
        .....
    );
}

when using standalone, following codes below:

$highlighter = Yii::createComponent(array(
    'class' => 'application.geshi.GeSHiHighlighter',
    'language' => 'php',
));
 
echo $highlighter->highlight('<?php echo "Hello World"; ?>');

tips: you can set the htmlOptions for code container by codes below:

$highlighter->containerOptions = array(
    'class' => 'cb_highlight',
);

BE ADVISED, only ID, CLASS, STYLE are supported.

Resources

Total 4 comments

#4321 report it
yiqing95 at 2011/06/25 10:24pm
please more careful , the demo code you give didn't work!

in the filter function it should be :

return array(
        array(
            'application.components.geshi.GeSHiHighlighter',
          /*  yours: 'class' => 'application.components.geshi.GeSHiHighlighter',*/
            'language' => 'html',
        ),
 
    );
  // and the alias is  prefixed by application.components.  not application.
  /* and you give a wrong method : $highlighter = Yii::createCompoent(array(
    'class' => 'application.geshi.GeSHiHighlighter',
    'language' => 'php',
     ));
     the 'createCompoent' should be "createComponent"
   */

just a little modify , :) anyway , it's a good extension .

#4005 report it
巡洋艦 at 2011/05/26 11:15am
so good!

It is a good extension, thanks!

#4004 report it
Francis.TM at 2011/05/26 10:37am
description already expanded

@yiqing95 as your comment, description already expanded hope you will find what you want to know. :-)

#4003 report it
yiqing95 at 2011/05/26 10:18am
the usage description is not enough !

看了你的主页才知道你跟我一样是中国人!呵呵 用法描述太少了,我不得不看源码,并从源码找他的根COutputProcessor ,原来是一个widget,所以你应该建议下载的文件应该放在那里 比如: components目录下或者是新建一个widgets目录(在components下或者protected下),不过放在extentions目录下也可以。还有最好加一个如果作为widget的示例用法,我现在还用不到这块所以先不研究你的扩展了!

Leave a comment

Please to leave your comment.

Create extension