SyntaxHighlighter component for Yii framework. ¶
This application component wraps SyntaxHighlighter by Alex Gorbatchev
Install ¶
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) Django Eclipse Emacs FadeToGrey MDUltra Midnight RDark ~~~
Usage ¶
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: ~~~ [html]
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_:
[html]
...~~~
This component makes use of the SyntaxHighlighter autoload feature, so that only the brushes used are actually loaded into the page.
Tricks ¶
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.
not working exactly
Hi I had used this but not working exactly. I configured as guide above.
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
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;
}
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: " "
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.
Yii 1.1: syntaxhighlighter extension CListView ajax pagination problem RESOLVED
We resolve it. Check by link and enjoy
Forum iSYSTEMS
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.