Go Down

Topic: Can we get Arduino style syntax coloring in the code box? (Read 4023 times) previous topic - next topic

dlloyd

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(ledPinledState);
  }
}


This was posted using php syntax coloring by using:

Code: [Select]
[table][td][php]your code[/php][/td][/table]
Without the white background:

Code: [Select]
[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?


PCWorxLA

Nice one!
That should be acceptable! :smiley-cool:

Ralf

graynomad

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

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

dlloyd

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]

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(ledPinledState);
  }
}

graynomad

#4
Oct 25, 2014, 12:08 am Last Edit: Oct 25, 2014, 12:21 am by Graynomad
 Just thought I'd give it a try without the white box

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(ledPinledState);
  }
}


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
Rob Gray aka the GRAYnomad www.robgray.com

MAS3

[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.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

dlloyd

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

dlloyd

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:

Code: (Arduino) [Select]
//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:



SurferTim

As I recall, if you use the "Edit - Copy for forum" selection in the IDE, you get the colors.
Quote
#include <SPI.h>
// test
void setup() {
 
}

void loop() {
 
}
...but you must use it between quote tags, not code tags.

dlloyd

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

Robin2

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

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

graynomad

#11
Oct 26, 2014, 11:52 pm Last Edit: Oct 27, 2014, 01:50 pm by Graynomad
If it's in quote tags it's a proportional font and some combinations are treated as bb codes, for example

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


Quote
for (int b = 0; b < 5; b++)
            array = b;
func(8);
Yes Robin I think it's essential that the edit timeout feature is removed.

EDIT (severel hours later): Looks like it has.


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

dlloyd

Changed title on first post.

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

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

pYro_65

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.

Quote
for (int b = 0; b < 5; b++)
            array[b] = b;
func(8);
Quote
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.
Forum Mod anyone?
https://arduino.land/Moduino/

dlloyd


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:

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

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

Go Up