עורך Rich Text בנושאים שובר תווי רווח בדרכים מרובות

Hi All!

In this topic, I will refer to other topics, but I believe I will describe a bigger issue than other reports mentioned.

My test environment

  • OS: MacOS 15.6.1
  • Browser: Google Chrome 139.0.7258.140 (Official Build) (arm64)

The original observation

I noticed that the Rich Text editor in the composer frequently breaks code blocks. Users started to post their code and logs in a single line, and I first thought that they made a mistake while copying their content to the composer. There were no white space characters between the posted lines at all, not just the line breaks.

Sometimes users posted multiple single-line code, losing the indentation in a YAML. Sometimes it was a multiline code highlighted as a single line, sometimes it was a single line in a code block. It happened too frequently, so I tested the Rich Text mode yesterday but waited with the reporting. Today, I could not reproduce that issue, but I found another way in the Rich Text editor to break line breaks in code.

I wasn’t sure if that was a bug, so I just discussed the issue with our moderators, waiting for the confirmation that the bug was fixed. Then it turned out we didn’t even find the same behavior, but all issues were related to white spaces. Except, I could not reproduce the issue mentioned by another moderator, but I realized it was because he copied the text from a code editor or terminal, and I copied it from my own previous code block from the forum, so the white space issue came differently.

Different ways to break the white spaces in code blocks

First way

  • Copy an output from a terminal
  • Paste the output to the composer in Rich Text mode like this (part of the output of runc without arguments)
COMMANDS:
   checkpoint  checkpoint a running container
   create      create a container
   delete      delete any resources held by the container often used with detached
  • You will see a multiline output, but the indentation is removed
  • Now realize you want a code block and make it one by selecting the text and clicking on the Code button.
  • Now the code is a little bit strange, because it looks like a code, but not as a code block. Switch back to markdown to see why and notice this:
`COMMANDS:`
`checkpoint  checkpoint a running container`
`create      create a container`
`delete      delete any resources held by the container often used with detached container`

Copy a code from another topic or another post in the same topic

Existing topic I found: `white-space` CSS property of clipboard data not respected when pasting in rich text editor

Of course, this is not the right way of copying in Discourse, as you have a “Quote” button for selected texts which usually works with parts of a code block as well, and you also have a copy button in the corner of each code block, but this is how I noticed the issue, and the copy button didn’t work either.

  • Copy a multiline code from an HTML page
  • Paste it into the composer in Rich Text mode
  • Notice that the line breaks are gone
  • At this point, you could think it is just in HTML, so make it a code
  • Line breaks did not come back

Use the Copy button in the upper right corner of a code block in another post

  • Move the mouse pointer above an existing code block
  • Notice that the small “Copy” button appeared in the upper right corner
  • Click on that button to copy the code
  • Paste it into the composer in Rich Text mode
  • Line breaks are kept, but the indentation is gone the same way as it happened when copying from HTML directly.
  • Make it a code block and get multiple single-line code without indentation

Probably fixed issue which happened when switching back to MarkDown

  • Write a code block in Rich text editor
  • See a perfectly good multiline code block
  • Switch back to MarkDown
  • See a single line instead of the code block
  • Notice that it is not a code block anymore, but if the text is long, you might miss that the indentation is gone too
  • Make it a code block
  • Post it and get a code block that contains a single line where line breaks are removed completely, not even a space kept

Again, this is the one I can’t reproduce today, and I haven’t searched for release notes to see if it was fixed, but I also couldn’t find this issue reported in other topics.

Conclusion

So it seems that the Rich Text mode has problems with code blocks in multiple ways. It makes moderation harder as we often assume that a user did not format their post properly, so we link our formatting guide, which wouldn’t work in Rich Text mode, but that is not the problem as guides can be modified. However, users actually try to format their post and fail due to the Rich Text editor.

Since the original issue I noticed was the one that is probably fixed by now, it seems to me that some users started with the Rich Text editor, didn’t like it, switched to Markdown, realized they broke the code blocks, tried to fix, but couldn’t and didn’t paste everything again.

Now at this point, I would also mention this topic about disabling the Rich Text editor completely: How can i set disable Markdown & Default to Rich Text

I link it because this was one of the first topics I found while searching for existing reports yesterday, and I just changed the default back to MarkDown. I stop here to avoid anyone reacting to this part, and I will probably add some notes in the other topic.

PS.: I used the proofreading feature on this post. It is amazing!

There is a dedicated bug report here:

לייק 1

Thanks! I thought I spent enough time on searching, but I didn’t find this one.

Hi @rimelek thanks for the detailed report, we appreciate it.

We added this in our backlog (and part of it is subjects we already started to work on) but it might take few weeks to get to it.

2 לייקים