11 years, 5 months ago.

how to add a code block to a question

I understand that code should be inserted between <<code>> <</code>> tags. When I do this, the pasted code does not keep the colors. please explain how to correclty insert a code block in a question. - Jim

3 Answers

james kain
poster
11 years, 5 months ago.

thanks all. Should have spotted the "editing tips" ... hidden in plan view!! j

Accepted Answer
11 years, 5 months ago.

First , you copy and paste code segment and then mark it as "code" using the tags.

11 years, 5 months ago.

Test! The following is pasted using <<code>> <</code>> as per editing tips. But as you say appears black only in preview. Lets see how it looks after posting!

#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

Ahhh, well it is in colour after posting, but not in preview, so all is OK. For anyone else (Not James!) who is unsure on editing, click on the <Editing tips> at the bottom right of the editing pane for clear instructions.

Make sure you put the block instructions at the beginning of a new line as shown.

posted by Kevin Hobbs 18 Nov 2012

The syntax highlighting is done by Javascript at the point that the page is loaded. In the preview the Javascript isn't run. I'll add a todo item to investigate whether we can do this.

posted by Stephen Paulger 20 Nov 2012