Go Down

Topic: How to post Arduino code with syntax highlight on Forum (Read 1 time) previous topic - next topic

May 30, 2020, 02:52 am Last Edit: May 30, 2020, 02:56 am by IoT_hobbyist
You can post the code on the forum with syntax highlight just like shown on Arduino IDE. For example

Code: see how to post code


/*
  Blink
  This example code is in the public domain.
  http://www.arduino.cc/en/Tutorial/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

How To

Use this online tool  to convert Arduino Code to BBcode and post the BBcode on Forum.

Note that:
  • You do NOT need to include [ code][ /code] tag
  • Before using this tool, It is better to format your code by pressing "ctrl + T" on Arduino IDE

ballscrewbob

Well that's a nice easy way to do things  :smiley-grin:

karma.

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

TheMemberFormerlyKnownAsAWOL

What happened to the "select" control?
The scrolling?

Whatever method you use, it is always advisable to use ctrl-T
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

#3
May 30, 2020, 09:32 am Last Edit: May 30, 2020, 09:33 am by IoT_hobbyist
The select and scrolling are only available in [ code] tag. However, in this forum, BBcode is disabled inside the [ code] tag. If we use the [ code] tag, we cannot do the syntax highlight.
Some other forums, we can use BBcode inside [ code] tag.

pert

Code tags serve another very important purpose beyond providing easy copy/paste and a scrolling window. Without it, the forum software can mistake parts of the code for bbcode markup. Take this code for example:
Code: [Select]
for (i = 0; i < 42; i++) {
  reading[i] = digitalRead(8);
}

now if I use your tool, it looks like this:
Code: see how to post code
for (i = 0; i < 42; i++) {
  reading = digitalRead(8);
}

It has pretty colors, but is also completely broken.

The fix would be for the tool to detect markup in the code and wrap it in nobbc tags.


I fixed it.

Code: see how to post code
for (i = 0; i < 42; i++) {
  reading = digitalRead(8);
}

pert

Getting closer, but not quite there. You fixed the smiley face, but not the italics. Note that the [i] is missing from the code.

lastchancename

#8
Jun 04, 2020, 04:53 am Last Edit: Jun 04, 2020, 04:53 am by lastchancename
Maybe I'm getting old, I appreciate the objective,  but Why ?
If it adds the colour feature fine, but to lose everything else seems to be lost time.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Ì fixed. I would be great if Arduino forum can create a new custom code tag without escaping BBcode. If so, we can combine the advantages of two method.

Code: see how to post code
for (i = 0; i < 42; i++) {
  reading[i] = digitalRead(8);
}

larryd

Pretty, but can't see why is it needed.

Attaching a sketch using 'code tags' allows us to scroll through a users code.

Wrapping code in extra formatting codes reduces the size of the sketch that can be displayed.




No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

lastchancename

I tend to agree, color-coding helps beginners and artists*, but after a few months coding experience, you see syntax & structure much faster with clear text.

It is useful while actually writing the code - to highlight blocks and the use of functions etc.  but I don't think it helps in passing the intent of the code between people.
If they need colour, they can drop the code into their preferred editor, and voila, it comes alive.

* nothing wrong with that at all, but it's like setting a speed limit for all drivers to keep learners safe.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up