-
Notifications
You must be signed in to change notification settings - Fork 4.7k
RichText: convert HTML formatting whitespace to spaces #12166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -297,11 +297,10 @@ function createFromElement( { | |
|
|
||
| const length = element.childNodes.length; | ||
|
|
||
| // Remove any line breaks in text nodes. They are not content, but used to | ||
| // format the HTML. Line breaks in HTML are stored as BR elements. | ||
| // See https://www.w3.org/TR/html5/syntax.html#newlines. | ||
| const filterStringComplete = ( string ) => { | ||
| string = string.replace( /[\r\n]/g, '' ); | ||
| // Reduce any whitespace used for HTML formatting to one space | ||
| // character, because it will also be displayed as such by the browser. | ||
| string = string.replace( /[\n\r\t]+/g, ' ' ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to replace
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, one of the issues this or fixes is exactly replacing line breaks with a space. |
||
|
|
||
| if ( filterString ) { | ||
| string = filterString( string ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-wrapwill preserve newlines, spaces, and tabs. But infilterStringCompletewe're only replacing newlines and tabs with spaces. As a consequence of this change, the editor will now show those consecutive spaces.Before this change:
After this change:
Is that a concern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For completeness, here's the same action in visual mode. No visual change, although under the hood the HTML doesn't add
nbsp.Before this change:
After this change:
I've noticed that with this change applied the leading spaces in the first line collapse before the post is reloaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that’s fine?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the rare case that the user want to have those spaces visible on the front end, I think they should insert those non breaking spaces themselves explicitly.