Testing new syntax highlighter code
Posted by gregster on 12 Feb 2007 in Activity log
If you wrap some code with a cgeshi tag a plugin library called GeSHi will provide some basic highlighting as below. Tags used in the below examples are:
HTML (4.01 is it apparently) [cgeshi_html4strict]
[/cgeshi_html4strict]
CSS
[cgeshi_css]div#pageFooter {
clear: both;
background-color: #fff;
width: 738px;
margin: 0 auto;
padding: 0 0 1ex 0;
}
p.baseline, p.baseline a {
border-top: 1px solid #ddd;
text-align: center;
font-size: 74%;
color: #aaa;
padding: 1ex;
margin: 0;
}[/cgeshi_css]
Javascript
[cgeshi_javascript]function TrimEndToTag(ElName){
var El = document.getElementById(ElName);
if (El != null){
s = El.value;
while ((s.charAt(s.length-1) != '>')&&(s.length>0)){
s = s.substring(0,s.length-1);
}
El.value = s;
}
return true;
}[/cgeshi_javascript]
XML
XML seems to be finicky. I keep getting illegal tag warnings from either b2 or GeSHi. I'll look at it again another time.
PHP
[cgeshi_php]<?php
$evousers = $DB->get_results('SELECT * FROM T_users ORDER BY user_ID');
foreach ( $evousers as $user )
{
// Access data using object syntax
echo $user->user_ID;
echo ' (';
echo $user->user_firstname;
echo ' ';
echo $user->user_lastname;
echo ')
' } ?>[/cgeshi_php] Java [cgeshi_java]/* Output: move to 0.0, 0.0 line to 72.0, 0.0 line to 72.0, 72.0 line to 0.0, 72.0 line to 0.0, 0.0 close */ import java.awt.Shape; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; public class MainClass { public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); PathIterator pi = s.getPathIterator(null); while (pi.isDone() == false) { describeCurrentSegment(pi); pi.next(); } } public static void describeCurrentSegment(PathIterator pi) { double[] coordinates = new double[6]; int type = pi.currentSegment(coordinates); switch (type) { case PathIterator.SEG_MOVETO: System.out.println("move to " + coordinates[0] + ", " + coordinates[1]); break; case PathIterator.SEG_LINETO: System.out.println("line to " + coordinates[0] + ", " + coordinates[1]); break; case PathIterator.SEG_QUADTO: System.out.println("quadratic to " + coordinates[0] + ", " + coordinates[1] + ", " + coordinates[2] + ", " + coordinates[3]); break; case PathIterator.SEG_CUBICTO: System.out.println("cubic to " + coordinates[0] + ", " + coordinates[1] + ", " + coordinates[2] + ", " + coordinates[3] + ", " + coordinates[4] + ", " + coordinates[5]); break; case PathIterator.SEG_CLOSE: System.out.println("close"); break; default: break; } } }[/cgeshi_java] Delphi [cgeshi_delphi]procedure TForm1.FormCreate(Sender: TObject) ; begin Image1.Transparent := False; Image2.Transparent := True; Image3.Transparent := True; with Image3.Picture.Bitmap do begin //middle of the image TransparentColor := Canvas.Pixels[24,24]; //actually not needed TransparentMode := tmFixed; end; end;[/cgeshi_delphi] Bash [cgeshi_bash]# save LD_LIBRARY_PATH if [ -n "$LD_LIBRARY_PATH" ]; then OLD_LIBRARY_PATH="$LD_LIBRARY_PATH" fi # add lib/core to LD_LIBRARY_PATH for readline support export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$EXIST_HOME/lib/core" JAVA_ENDORSED_DIRS="$EXIST_HOME"/lib/endorsed $JAVA_CMD $JAVA_OPTIONS $OPTIONS \ -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \ -jar "$EXIST_HOME/start.jar" backup $* if [ -n "$OLD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH="$OLD_LIBRARY_PATH" fi[/cgeshi_bash]
[cgeshi_html4strict][/cgeshi_html4strict]
[cgeshi_css][/cgeshi_css]
[cgeshi_javascript][/cgeshi_javascript]
[cgeshi_xml][/cgeshi_xml]
etc.HTML (4.01 is it apparently) [cgeshi_html4strict]
some content
' } ?>[/cgeshi_php] Java [cgeshi_java]/* Output: move to 0.0, 0.0 line to 72.0, 0.0 line to 72.0, 72.0 line to 0.0, 72.0 line to 0.0, 0.0 close */ import java.awt.Shape; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; public class MainClass { public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); PathIterator pi = s.getPathIterator(null); while (pi.isDone() == false) { describeCurrentSegment(pi); pi.next(); } } public static void describeCurrentSegment(PathIterator pi) { double[] coordinates = new double[6]; int type = pi.currentSegment(coordinates); switch (type) { case PathIterator.SEG_MOVETO: System.out.println("move to " + coordinates[0] + ", " + coordinates[1]); break; case PathIterator.SEG_LINETO: System.out.println("line to " + coordinates[0] + ", " + coordinates[1]); break; case PathIterator.SEG_QUADTO: System.out.println("quadratic to " + coordinates[0] + ", " + coordinates[1] + ", " + coordinates[2] + ", " + coordinates[3]); break; case PathIterator.SEG_CUBICTO: System.out.println("cubic to " + coordinates[0] + ", " + coordinates[1] + ", " + coordinates[2] + ", " + coordinates[3] + ", " + coordinates[4] + ", " + coordinates[5]); break; case PathIterator.SEG_CLOSE: System.out.println("close"); break; default: break; } } }[/cgeshi_java] Delphi [cgeshi_delphi]procedure TForm1.FormCreate(Sender: TObject) ; begin Image1.Transparent := False; Image2.Transparent := True; Image3.Transparent := True; with Image3.Picture.Bitmap do begin //middle of the image TransparentColor := Canvas.Pixels[24,24]; //actually not needed TransparentMode := tmFixed; end; end;[/cgeshi_delphi] Bash [cgeshi_bash]# save LD_LIBRARY_PATH if [ -n "$LD_LIBRARY_PATH" ]; then OLD_LIBRARY_PATH="$LD_LIBRARY_PATH" fi # add lib/core to LD_LIBRARY_PATH for readline support export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$EXIST_HOME/lib/core" JAVA_ENDORSED_DIRS="$EXIST_HOME"/lib/endorsed $JAVA_CMD $JAVA_OPTIONS $OPTIONS \ -Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \ -jar "$EXIST_HOME/start.jar" backup $* if [ -n "$OLD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH="$OLD_LIBRARY_PATH" fi[/cgeshi_bash]
This entry was posted by Greg and filed under Activity log.