Can we get Arduino style syntax coloring in the code box?

The following is a section of code from the BlinkWithoutDelay example:

void loop()
{
  // here is where you would put code that needs to be running all the time.

  // check to see if it is time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

This was posted using php syntax coloring by using:

[table][td][php]your code[/php][/td][/table]

Without the white background:

[php]your code[/php]

Certain characters (in comments) get converted to the HTML char code (i.e. '), however I think the overall result is much more readable.

Is this an acceptable method to post code?

Nice one!
That should be acceptable! :sunglasses:

Ralf

Looks OK to me, but that's not a monospaced font though is it? That is an issue for code.


Rob

Graynomad:
Looks OK to me, but that's not a monospaced font though is it? That is an issue for code.


Rob

Ahh, right ... could I borrow your glasses?

new bbCode for syntax coloring:

[table][td][tt][php]your code[/php][/tt][/td][/table]

without white background:

[tt][php]your code[/php][/tt]
[php]void loop()
{
  // here is where you would put code that needs to be running all the time.

  // check to see if it is time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}[/php]

Just thought I'd give it a try without the white box

[php]void loop()
{
  // here is where you would put code that needs to be running all the time.

  // check to see if it is time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}[/php]

looks pretty good either way I think. For large code snippets the normal tag might be better because that will (when it's fixed) give scroll bars.

So are [ tt ] and [ php ] standard BB codes?


Rob

[tt] is new to me, [php] has been around for a while.
[php] also works on vBulletin boards, [tt] doesn't seem to exist there.

Yes, it's standard. [tt] is the BB Code that gets entered when you press the "Teletype" button in the text editor.

http://wiki.simplemachines.org/smf/Alphabetical_list_of_all_bulletin_board_codes

It seems that SMF Syntax Highlighter or something similar is already implemented in this forum. The code tag can take a parameter without complaining, so if we use:

[code=Arduino]//your code[/code]

we get the parameter displayed in the code box title:

//your code

I would like to propose to the forum administrators that syntax coloring for Arduino be added to the necessary translation file(s) on the server. I think it would be an awesome feature to have this as default. Then after using code tags as normal, a code box would be created having code colored like this:

As I recall, if you use the "Edit - Copy for forum" selection in the IDE, you get the colors.

#include <SPI.h>
// test
void setup() {

}

void loop() {

}

...but you must use it between quote tags, not code tags.

Yes, that's the desired effect. (nice - I couldn't replicate it here, at least in Preview).

This is a very good example of why we should be able to edit our posts when we like - see other discussion here.

...R

If it's in quote tags it's a proportional font and some combinations are treated as bb codes, for example

for (int b = 0; b < 5; b++)
            array[b] = b; 
func(8);

for (int b = 0; b < 5; b++)
array = b;
func(8);[/quote]
Yes Robin I think it's essential that the edit timeout feature is removed.
EDIT (severel hours later): Looks like it has.
______
Rob

Changed title on first post.

This is as close as it gets (php style)...

//<?php>
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
  ledState = HIGH;
else
  ledState = LOW;

Graynomad:
If it's in quote tags it's a proportional font and some combinations are treated as bb codes, for example

Rob

You can escape special text with 'nobbc' tags, like some have already used in posts here.

for (int b = 0; b < 5; b++)
array[b] = b;
func(8);

As I recall, if you use the "Edit - Copy for forum" selection in the IDE, you get the colors.

The feature 'copy for forum' now simply wraps the syntax in a code box (1.5.6 and up), no more quote styling.


Thank you ffissore for submitting this as a feature request.

I would like to suggest that this feature be implemented in a way that requires no special action(s) by the user.

Since parameters are accepted by some BB codes (i.e.

[size=36pt], [img width=200]

), then it should be possible to add some style parameters to

[code]

, where the Arduino style is default.

Examples:

[nobbc][code][/nobbc]           Arduino syle syntax coloring  
[nobbc][code=plain][/nobbc]     No syntax coloring
[nobbc][code=c++][/nobbc]       C++ syle syntax coloring
[nobbc][code=php][/nobbc]       PHP syle syntax coloring

This way, pressing in the editor will use Arduino style coloring by default.

This award winning syntx highlighter is can be easily configured to Arduino coloring:

Demo

GeSHi - Generic Syntax Highlighter

GeSHi - SMF

Second time today - I just wanted to comment of this thread so I could keep an eye on it, (via my posts) seeing as I never get any post or message notifications anymore 8)

Neither do I.

Surprise surprise. I awoke this morning to find ten forum post notifications in my inbox. Hmm, I wonder if I'll get one for this post 8)

Must be your birthday.
Congratulations !