While testing another bug, I posted this text to try.discourse.org:
problem_post.txt (2.5 KB)
The editor preview shows line breaks in the code block, but the post itself renders without the line breaks.
The discussion revolves around the issue of code fences inside a list not rendering correctly in Discourse. clay reported the issue, where line breaks in a code block disappear when posted, but appear in the edit or preview. codinghorror demonstrated the problem with invalid language keywords. clay showed that the issue only occurs when the code block is nested under a bullet point. As a workaround, johnmuhl suggested using indented code blocks instead of backtick code blocks. The issue has since been fixed by eviltrout in the master branch of Discourse.
While testing another bug, I posted this text to try.discourse.org:
problem_post.txt (2.5 KB)
The editor preview shows line breaks in the code block, but the post itself renders without the line breaks.
This can happens when an invalid language keyword is used, let’s see
line above
size(600, 400);
println("width " + width);
println("height " + height);
versus
line above
size(600, 400);
println("width " + width);
println("height " + height);
line above
``` bleh
size(600, 400);
println("width " + width);
println("height " + height);
```
versus
line above
```
size(600, 400);
println("width " + width);
println("height " + height);
```
The code seems to work fine when it is not nested under a bullet.
Some list
size(100,100);
ellipse(x,y,100,100);
Another list item
versus…
size(100,100);
ellipse(x,y,100,100);
It’s the backtick code blocks inside list which are not standardized across implementations (the preview and output differing seems like a real bug though). But you can use indented code blocks as a workaround until Discourse switches to markdown-it (which supports what you are trying to do).
1. first
size(x, y);
print(1);
2. second
size(x, y);
print(1);
3. third
4. and so on
first
size(x, y);
print(1);
second
size(x, y);
print(1);
third
and so on
Thanks I’ve fixed this in master (it’s currently being deployed):
https://github.com/discourse/discourse/commit/f2db4bfcf3ee6dc024ef1bee91acf66049753501