Priority/Severity:
Medium
Platform:
Operating System
- Windows 11
Browser
- Google Chrome 139.0.7258.128
Discourse
028c90dd5e7a2799ea5b6e963f71fc0222681943
Description:
Text copied from some sources may be stored in the clipboard in a formatted form (text/html
type) in addition to plaintext (text/plain
).
When text is pasted into the composer, if a formatted data type is present in the clipboard then this data is used instead of the plaintext type.
By default, whitespace in HTML content is collapsed. This behavior can be controlled via the white-space
CSS property.
When pasting in the composer when in “rich text editor” mode, the
white-space
CSS property of the clipboard data is not respected. This results in whitespace always being collapsed in the pasted content. In cases where the source content had a white-space
property set to the pre
value, this results in the pasted content being difficult to read, and incorrect in cases where the whitespace of the source content had technical significance.
Reproducible steps:
- Create an HTML file with the following content:
<html> <body> <span style="white-space: pre">foo bar </span> </body> </html>
- Open the file in your web browser.
Note that the whitespace of the page content is not collapsed:foo bar
- Copy the content of the web page.
- Open the post composer.
- Put the composer into the “rich text editor” mode.
- Paste the copied content.
Instead of having the same format as the copied content, the whitespace of the pasted content was collapsed:
foo bar
Additional context:
I see that ProseMirror does support white-space: pre
:
The fault does not occur when using the composer in the “Markdown editor” mode.
The fault does not occur if the content is pasted into a code block instead of into the normal editor mode. It is true that in many cases it would be most appropriate to place the content that uses something like white-space: pre
in a code block. However, it is fairly common for users to apply formatting retroactively by adding the content to the composer, selecting the content, then using the composer toolbar to apply the formatting (as opposed to the alternative approach of triggering a codeblock prior to adding the content).
I found this to be a useful tool for examining the raw data of the clipboard content:
I am able to reproduce the fault on try.discourse.org in “safe mode”.