Trailing code block newlines don't auto-format in "view" mode

Description of the bug
SN commonly removes newlines when viewing notes, even if the raw text has them, which makes for a nice reading experience. With code blocks, the trailing newlines persist, and I think it would make sense for them to not render in “read” view

App & Version
MacOS v3.0.6

Screenshots / Screen Recording

In most Markdown implementations, trailing whitespace within code blocks is typically preserved and rendered as it is. This happens as Markdown processors treat code blocks as preformatted text and don’t modify the content inside them, including whitespace. It’s unlikely we will modify this.

Is there a particular reason why you’d like this behaviour @fuzzy.beach? Certain workflows like copy / pasting that are introducing a trailing new line?

Fair enough, this one is not a big deal and I can write some script to take care of it. You’re spot on with the cause, when copying code blocks along with text this tends to happen (from Notion for instance)

1 Like

For sure, I reckon the better solution would be to modify the paste processor to “auto-trim” any trailing whitespace from code blocks. But then if you’re intentionally adding whitespace to the end of your code-blocks then this would be annoying.

For now I’m going to mark this as “Intended Behaviour”, however as always if more use cases crop / anyone else has any thoughts we can always reopen this.

1 Like