Forum Code Formatting and Syntax Highlighting

To format code in this forum you need to surround the code with three backticks (```). For example, typing this...

```
fn main() {
    println!()
}
```

...will be rendered as highlighted Rust code, like so:

fn main() {
    println!()
}

You can also tell the forum software which language you're using by adding the language after the opening backticks.

```cpp
#include <iostream>
int main() {
  std::cout << "Hello World!";
}
```

Will appear with highlighting as:

#include <iostream>
int main() {
  std::cout << "Hello World!";
}

Other supported language names include Rust, javascript, python and many more.

14 Likes

Seems like pinning this thread would be fine?

6 Likes

This is part of "markdown", a standard text formatting syntax not unique to Github. These days most implementations I know of are using the CommonMark spec with some extentions. Here are some links:

I've also personally used ```s and other bits of markdown on StackOverflow, Slack and Discord, so it's pretty close to universal.

3 Likes

Since this has now been pinned (thanks!) I've removed the last note that lxrec is responding to, but I'll copy it here for posterity:

Summary

However this way of posting code isn't so obvious. It relies on a new user being aware of the github syntax and guessing that this forum uses the same syntax. I didn't when I first arrived and frequently new users post code that's hard to read because they aren't aware of how to format it for this forum's software.

Could there be somewhere that explains this placed where new users can see it?

I didn't realize that the syntax was now in the CommonMark spec. Thanks for the correction.

2 Likes