Yii 1.1: syntaxhighlighter

Wrapper for the Alex Gorbatchev SyntaxHighlighter

SyntaxHighlighter component for Yii framework.

This application component wraps SyntaxHighlighter by Alex Gorbatchev


Unpack extension into a directory of your choice, the extensions directory would be a good choice.

Add to config/main.php:

'components' => array(
            'syntaxhighlighter' => array(
                'class' => 'ext.JMSyntaxHighlighter.JMSyntaxHighlighter',

If you want a theme other than the default:

'components' => array(
            'syntaxhighlighter' => array(
                'class' => 'ext.JMSyntaxHighlighter.JMSyntaxHighlighter',
                'theme' => 'Django',

You can choose from the following themes:

Default (the default if none provided)


Insert this code where you want the syntaxhighlighter script to be:

<?php Yii::app()->syntaxhighlighter->addHighlighter(); ?>

This could be in your main layout, but it's up to you.

The script will highlight any pre tag having the "brush" class:

<pre class="brush : php">
function Hello($world) {
    echo 'Hello ' . $world;

Available brushes are:

    _Brush_                 :   _Language_
    applescript             :   AppleScript
    actionscript3 as3       :   AS3
    bash shell              :   Bash
    coldfusion cf           :   ColdFusion
    cpp c                   :   Cpp
    c# c-sharp csharp       :   CSharp
    css                     :   Css
    delphi pascal           :   Delphi
    diff patch pas          :   Diff
    erl erlang              :   Erlang
    groovy                  :   Groovy
    java                    :   Java
    jfx javafx              :   JavaFX
    js jscript javascript   :   JScript
    perl pl                 :   Perl
    php                     :   Php
    text plain              :   Plain
    py python               :   Python
    ruby rails ror rb       :   Ruby
    sass scss               :   Sass
    scala                   :   Scala
    sql                     :   Sql
    vb vbnet                :   Vb
    xml xhtml xslt html     :   Xml

For example, to highlight a bash script, you can use either bash or shell:

<pre class="brush : shell">...</pre>

This component makes use of the SyntaxHighlighter autoload feature, so that only the brushes used are actually loaded into the page.


TinyMCE is great, but it does not want to leave the <pre> tags alone! Don't worry, there's a solution to this problem: Grab and install the Wysiwyg Pre Element Fix and enjoy! :) Just in case: the Pre Element Fix has been attached to this page as well.


Total 5 comments

#19712 report it
iSystems at 2015/12/25 02:18pm
Yii 1.1: syntaxhighlighter extension CListView ajax pagination problem RESOLVED

We resolve it. Check by link and enjoy Forum iSYSTEMS

#19711 report it
iSystems at 2015/12/25 11:28am
List View AJAX Problem

CListView showing syntaxhighlighter fine. After clicking to pagination, any page, new content not showing as syntaxhighlighter. Program not finding brushes.

Now I am trying to resolve it, if you have any resolved article, share for US.

Thank you. Best regards iSYSTEMS.am.

#18289 report it
Gregurco at 2014/10/11 06:24pm
Class container

The code is wrapped in class container, that is used in bootstrap. And if you check it in firefox, you will notice that the line of code is not on the same level with the number of this line. Because in bootstrap class container has next rule: content: " "

#16646 report it
Lexne at 2014/03/14 10:36am
Works perfectly

Works perfectly for me. Up and running in less then 5 minutes.

However, if I would not like to show the lines. Can I remove those with some easy syntax?

function Hello($world) { echo 'Hello ' . $world; }

#9665 report it
nirmalroka at 2012/09/02 08:54am
not working exactly

Hi I had used this but not working exactly. I configured as guide above.

my code here

I used the same in my text area not used any editor.

In my view I get missed first part of <?php and other paramerter. When i use <?php Yii::app()->syntaxhighlighter->addHighlighter(); ?>

in view where i display content than it show different al over the code

Leave a comment

Please to leave your comment.

Create extension