thunder icon indicating copy to clipboard operation
thunder copied to clipboard

Code blocks (I think?) don't word wrap

Open machinaeZER0 opened this issue 1 year ago • 4 comments

Apologies if these are a different element than a code block! I've noticed for some time that the type of text shown below displays as a single line on mobile unless line breaks are manually entered - scrollable, but not super ideal presentation wise.

Screenshot_20240909-124109.png (Post in question can be viewed here: https://lemmy.zip/post/22426238)

Is it possible to tweak this behavior, or is it technically a feature of that particular formatting?

machinaeZER0 avatar Sep 09 '24 16:09 machinaeZER0

Hey @machinaeZER0, thanks for the question! I won't say that we would never implement an option for wrapping code blocks, but I will say that it's very intentional that they don't wrap. When you're dealing with code, line breaks often have specific meaning, and you don't want any additional ones to be introduced automatically by the tool you're using to view the code. That's exactly why there's a separate option in markdown for code formatting: so that it doesn't get altered in any unintentional way.

You'll notice that the Lemmy web UI renders the code blocks in exactly the same way. Even though my monitor is obviously much wider than my phone, I still have to scroll horizontally to view all of the text.

image

In my opinion, the real problem is that the poster used a code block at all, since they weren't referencing code. They should have used a quote block, which is perfect for quoting text, as they were doing, and it would wrap the text.

I hope that makes sense, and I hope it doesn't come across as putting down your request at all. I just wanted to provide some clarification for why things work the way they do.

micahmo avatar Sep 09 '24 17:09 micahmo

Thank you, I had a feeling this might be the case! Do you think it would be more trouble than it's worth to have a "word wrap code blocks" option in settings? I could see it being a handy option for laypeople who aren't coders/a good catch all option since people will misuse code blocks in this way from time to time.

Obviously the people posting should be using the right block for the right tool, so I can totally see why we wouldn't want to "waste" dev hours on supporting unintended behavior, so mostly just thinking out loud :) either way, appreciate your reply/explanation (as always)!

machinaeZER0 avatar Sep 09 '24 17:09 machinaeZER0

Do you think it would be more trouble than it's worth to have a "word wrap code blocks" option in settings?

I don't think that's a bad idea at all. We can keep this issue open for just that request. However I just can't promise that it'll be a high priority.

P.S. One tip that might help is to long-press > Text Actions > View Comment Source. The comment will be displayed in raw markdown, and it will all be wrapped. Maybe it'll help. 😊

image

micahmo avatar Sep 09 '24 17:09 micahmo

Ohh, that is useful! I'll keep that in mind for the future :) thanks Micah!

machinaeZER0 avatar Sep 09 '24 17:09 machinaeZER0