Javascript syntax highlighting

A great example of useful JS.
  1. We have examples of computer code on our pages.
  2. Want all code to be syntax highlighted (color-coded).
  3. Do not want to have to hand highlight it.
  4. So want page on disk to be un-highlighted. When sent to client, it is highlighted by client-side JS before being displayed.
We can use this library from Google:


How to use

"View Source" here to see how to use:
  1. Include the JS.
  2. Mark the "pre" elements to be highlighted.
  3. (Optional) Include a style in CSS.
"View Source" here to see:
  1. I did not have to highlight the code myself.
  2. I made my own CSS.


C++ code

#include <stdio.h>
#include <stdlib.h>  

// comment

main ( int argc, char **argv )
{
 double lamb = atof ( argv[1] );
 double x = atof ( argv[2] );   

 for ( int i=1; i<=30; i++ ) 
 {
   printf( "%.5f \n", x );
   x = lamb * x * (1-x);
 }           
}

XML

<?xml version="1.0" encoding="UTF-16"?>
<soml xmlns="https://w2mind.org/soml" version="1.0">
<continuerun runid="1250522178060" type="response">
<action value="24"/>
<score>13, 860 alive</score>
<state>perceivedFatShortage:0.3965525064304313;
perceivedCarbohydrateShortage:0.12797975235558348;
perceivedProteinShortage:0.46190554471641926;
animalPermanentInjury:0.0;
dangerousPlacePerceptionStimulus2:[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
irrelevantAnimalPerceptionStimulus2:[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0];
preyInAnimalSquare:false;
fruitFoodInAnimalSquare:false;
cerealFoodInAnimalSquare:false;</state></continuerun></soml>