Code Blocks on Discuss aren't always rendering correctly


As the title says, Code Blocks sometimes render incorrectly (while writing my own posts) on Discuss. I used to create them using triple backticks, optionally with a language identifier, GitHub Flavored Markdown style, for example:

# complex one-liners never have comments

Note: the snippet above is created using a Preformatted Text block (indent by 4 spaces), which is not the same. It lacks syntax highlighting, causing a snippet to become hard to read.

However, a snippet written with that syntax does not always seem to work anymore. Here’s the same snippet without the preformatted text block indentation:

# complex one-liners never have comments

… which of course works fine now that I want to create a topic about it, even in the preview to the right. When I replied to another post an hour ago a similar snippet did not work. Using the example above, it would render the triple backticks followed by bash as a single backtick followed by bash, the comment as a markdown title and the one-liner as normal text. I should have taken a screenshot. I now edited the post to change the markup from preformatted text to code blocks and it now also works there.

I would cancel the creation of this topic, but it’s happened to me before in the passed couple days and I have an example where it did not work as expected with proof I am not crazy :smile: . In this reply I could not get code blocks to work either. I tried many different things and at some point during my experimentation I accidently placed 4 opening backticks instead of 3 (it is still closed with only 3 backticks), which to my surprise rendered it correctly:

Has anyone else experienced code blocks being rendered incorrectly?


I just had a similar problem where the preview correctly renders my code but the post prints everything in one line (Luckily I have a screenshot because after a few minutes the post rendered correctly too).

I’ve tried everything:


``` coffee



``` Coffee

Edit: Actually I found my mistake :confused:
I had to add an empty line before the code block ( but still: It rendered correctly in the preview ! )

Some text



I think this bug is fixed now, as of a day or so ago.


Code blocks also render incorrectly when the line with the closing backticks contains anything other than the backticks and a newline. This is especially frustrating on mobile phones, where sometimes a space is automatically added after the backticks. It will treat the block as if it was written with just single backticks, and newlines behave very weird:

someFunc = ->
  do stuff

In the code above I put a newline after the coffee and after the ->, but only the one after coffee is respected (I also tried this with more code after someFunc but it all gets squished into 1 line). When I put a space before or after the coffee, or before the closing backticks, newlines are respected again, but indentation isn’t. I’d think it would be safe to ignore whitespace on the backtick lines, or are there reasons not to?

PS How can I get backticks in the code blocks? I tried escaping them with a \ but that doesn’t seem to work.


But that doesn’t work in Discourse right now.