Syntax highlighting / Code blocks

A common problem with posts involving code segments is that users either simply paste the entire code blocks, or they do use the “Preformatted text” button, but the code still wouldn’t be represented properly, because the button defaults to an indentation by 4 spaces. Both approaches don’t generate desirable results. Hence we frequently have to explain to users how to format code properly (triple-backticks), or fix up the formatting ourselves (I do this almost every day, and it’s quite annoying!!)

I thought that, at least for those users who discovered the formatting button in the toolbar, we should default to triple-backticks instead of 4 spaces. We can change the respective setting at http://discourse.psychopy.org/admin/site_settings/category/posting
code formatting style is currently set to 4-spaces-indent. We should probably change it to code-fences.

Clicking on the respective toolbar button would then generate a block embedded in triple-backticks when the cursor is placed at the beginning of a new line, and single-backticks otherwise. Do you think this would be a good (better) default? Thanks!!

3 Likes

Anything to reduce the problem would be good. In pasted-in code, # characters mean that very comment gets turned into top-level heading formatted text, which is particularly annoying.

I find I can’t actually type a triple-backtick in messages as an example (it must work as an escape sequence in some way, although some of you wizards seem to have figured out how to do it…

@Michael, to get backticks to show up, you put a backlash before each one, so to get ``` , I typed \`\`\`, though just now I actually had to enter \\\`\\\`\\\` to escape the slash and get that to show up right, but then I actually (help!) had to enter \\\\\\`\\\\\\`\\\\\\` (it never ends…!)

But seriously, absolutely in favor of anything to make this better, glad @richard brought it up.

1 Like

Ah cool! I only knew how to place them on a separate line, like this:

```

This can be achieved by prepending four space characters.

1 Like

Cool, yes. It’s done.

1 Like