-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Prevent stray line breaks in RichText after pasting (e.g., from Google Doc) #15372
Conversation
@youknowriad @jorgefilipecosta @nerrad I just added some unit tests, and slightly changed the title (as it's not really about leading line breaks). Is there anything missing here? |
// are not phrasing content. | ||
if ( inline && ! isPhrasingContent( node ) && node.nextElementSibling ) { | ||
// are not phrasing content and no comments. | ||
if ( inline && node.nodeType !== COMMENT_NODE && ! isPhrasingContent( node ) && node.nextElementSibling ) { |
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.
Can these comments not be stripped beforehand? I think we'll need to add a filter to deepFilterHTML
, right after specialCommentConverter
.
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.
Hm, I can take a stab at it, sure. However, that same new filter would also be required in filterInlineHTML
, right? This function, too, calls removeInvalidHTML
.
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.
Would be nice to explore https://github.com/WordPress/gutenberg/pull/15372/files#r282800896.
Closing in favor of #15557. |
Description
When pasting something from a Google Doc into a
RichText
-based block, I ended up having a stray (leading) line break.Having chased through quite a few files and functions, I finally found that the culprit is the (internal)
cleanNodeList
function in@wordpress/blocks
(src/api/raw-handling/utils.js
).This function inserts a line break ( i.e., ultimately, a
<br>
tag) after non-phrasing-content elements.The problem with Google Docs, as with potential other sources, is that there are HTML comments, and they, too, would trigger insertion of line breaks.
Steps to Reproduce
RichText
component.The actual problem is the
<!--StartFragment-->
comment node.How has this been tested?
Copy-and-paste content from a Google Doc into a
RichText
component. No leading line break. 😉Screenshots
Types of changes
Insertion of line breaks after comment nodes is now being prevented.
Checklist: