Up, not North

Arduino code highlighting for the web

February 4th, 2010

I noticed that there didn’t seem to be any Arduino-specific syntax highlighting available for the web, so I took it upon myself to make an Arduino “brush” for the popular SyntaxHighlighter by Alex Gorbatchev. Since the size of the file supposedly affects performance, I made two versions: a “lite” version that includes all the core Arduino functions and constants, plus the Serial library; and a “full” version that also includes the EEPROM, Ethernet, Firmata, and Wire libraries, as well as (and this is where it gets big) the full set of ATMega168 keywords and macros. Here they are in action on some dummy code.

Here’s the “lite” version:

/* This is a multi-line
comment */
#define OUTPIN 11
int thisisavariable = B10011;
boolean isAdvanced = false;
void setup() {
  Serial.begin(9600); // This is an in-line comment
  pinMode(11,OUTPIN);
}

void loop() {
  Serial.println("This is a string!");
  if(thisisavariable < 10e4){
    digitalWrite(11,HIGH);
  }
  if(isAdvanced){
    ADCSRA |= (1 << ADSC);
    sei();
  }
}

And this is the “full” version:

/* This is a multi-line
comment */
#define OUTPIN 11
int thisisavariable = B10011;
boolean isAdvanced = true;
void setup() {
  Serial.begin(9600); // This is an in-line comment
  pinMode(11,OUTPIN);
}

void loop() {
  Serial.println("This is a string!");
  if(thisisavariable < 10e4){
    digitalWrite(11,HIGH);
  }
  if(isAdvanced){
    ADCSRA |= (1 << ADSC);
    sei();
  }
}

As you can see, I’ve italicised the AVR keywords and macros to distinguish them from the Arduino ones.

I’m making the Javascript files for the brushes freely available, so do with them as you will; that said, I’d love to know if you improve them, and I’d appreciate it if you gave me credit and/or a link back here if you redistribute them!

Lite Arduino brush
Full Arduino brush

§ 2 Responses to “Arduino code highlighting for the web”

§ Leave a Reply to darKing

*

Post Information