[How to] Post correctly formatted and colorized code on the forum?

Continuing the discussion from Ruby backtick returns nothing!:

Triple backtick delimiter lines.


  • image

Backquote character key on US keyboard.


If it is error message text (or some other plain text that contains <, >, #, or other characters that can confuse Discourse markdown,) then specify “text” as a lexing language:

```text
paste error message here
```

If it is Ruby, then:

```ruby
# code here
```

If it is Javascript, then:

```javascript
/* js code here */
```

If it is HTML, then:

```html
<!-- html here -->
```

If it is C, then:

```c
// C code here
```

… etc. (Discourse code lexer recognizes the major programming languages.)