Javascript syntax highlighting
A great example of useful JS.
- We have examples of computer code on our pages.
- Want all code to be syntax highlighted (color-coded).
- Do not want to have to hand highlight it.
- 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:
- Include the JS.
- Mark the "pre" elements to be highlighted.
- (Optional) Include a style in CSS.
"View Source" here to see:
- I did not have to highlight the code myself.
- 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>