Line breaks in code blocks don't work without a linebreak above

AI-generated summary

A bug was reported where line breaks in code blocks disappeared after editing a post. gerhard initially thought it might be a regression, but codinghorror explained that a blank line above the code block is required to maintain line breaks. gerhard noted that this wasn’t an issue when the post was created two weeks ago, and codinghorror suspected it might be related to changes made by sam. The issue was further investigated, and sam discovered that incorrect “hoisting” of code blocks was the root cause. sam fixed the hoisting issue, but noted that the rendering engine needs further improvement. The fix was implemented in this commit.

I have a few code blocks inside lists in my “Importing from phpBB3” topic. They looked fine when I posted this a few days ago. But now, after a small edit with insignificant changes, the line breaks inside the code blocks are gone.

The preview still looks fine:

The actual post however looks wrong:

Is this a regression or is there something wrong with my post?

1개의 좋아요

Something’s wrong here. Will have a look.

1개의 좋아요

Has already been reported. You need a blank line above or that will happen.

You also really ought to use 4 space indent rather than fenced code blocks when you don’t need syntax highlighting.

1개의 좋아요

The strange thing is, it worked when I posted it two weeks ago…

Could be related to @sam’s changes to hack in <table> support, don’t know.

Ok, I changed the way I format the code blocks for now. The thing is, I kinda like the bash syntax highlighting. :wink:

The issue here really is why is the preview different than the cooked post?

4개의 좋아요

I have a hunch on this.

We never correctly

hoisted
code blocks

and this incorrect hoisting, though not impacting the client that uses ember initializers to initialize dialects, did heavily impact the server that uses a different paradigm.

I fixed hoisting and unhoisting… but our architecture needs some TLC here, we need to split off the rendering engine into a cleaner, independent, multisite friendly piece.

https://github.com/discourse/discourse/commit/568adc49c09c4964ef3168dfd1fa12c2fb05203b

3개의 좋아요