Displaying code

Is the only way to display code by manually indenting the lines by 4 spaces?

I use the

3 backticks[code type]
code
3 backticks
way of doing it eg.

```CSS
div {
 border: 1px solid #F00;
}
```

for

div {
 border: 1px solid #F00;
}

OK easier than manually putting 4 spaces on every line but still not as easy as clicking a button.

I will give it a go next time.

Use this button in the editor:

Just highlight the code and hit it.
It will deal with both inline and block snippets.

1 Like

I’ll make this my “Did you Know…” for today :smile:

2 Likes

I hit the button then started writing the code and it only highlighted the first line so I need to write my code first and then select it and hit the button.

Yep. Unfortunately. I find the backticks a lot easier in that scenario (if you ask me)

1 Like

Indeed

Posted Did you know... (about Discourse) - #11 by cpradio

For myself I have been using a little of Markdown and BBCode. I do like the fact that I can hit those little buttons. Easier to remember. lol

It is confusing
bbcode?
markdown?
GUI?

I wish I knew the definitive “guide”. I usually use “3 backticks” and it works. But if someone knows of a case where it doesn’t work, please speak up.

From what I have seen that is the way that always works. It is the other ways that don’t always work.

I prefer the button, TBH, but I’ve also been in the habit of posting code blocks that I indent as a block on my code editor … meaning that each line is already indented as necessary.

This has been easiest for me:

  1. write code in sublime
  2. copy
  3. add backticks to post
  4. paste

Manually inserting whitespace is painful.

1 Like