Repository navigation
Conversation
Pasted HTML often wraps long lines with a line break in place of the space between two words. decaporg#7440 removed every line break from text nodes to fix extra blank lines around pasted content (decaporg#7364), which merged those words. Line breaks inside text and between inline elements now become a space, whitespace next to block elements is still dropped, and line breaks in <pre> are kept. Fixes decaporg#8094
👷 Deploy request for decap-cms pending review.Visit the deploys page to approve it
|
Word pastes a manual line break as `<br>\r\n`. The line break after the `<br>` became a leading space on the next line. Treat `<br>` like a block boundary, so whitespace next to it is dropped. Refs decaporg#8094
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #8094
Pasting rich text into the
markdownwidget merges words that are separated by a line break in the pasted HTML (first\r\nsecond→firstsecond). Many applications wrap long lines in the HTML they put on the clipboard and use a line break in place of the space between two words. Browsers render that line break as a space.#7440 fixed extra blank lines around pasted content (#7364) by removing every line break from text nodes. That is correct for whitespace-only text between tags (
<body>\n<p>), but it also removes line breaks inside text.This PR keeps the #7364 fix and handles line breaks in text nodes as whitespace:
<br>is dropped too, so a manual line break from Word (<br>\r\n) does not leave a leading space on the next line,<pre>are kept, as whitespace is significant there (before this PR,#7440also removed them from pasted code blocks).Text without line breaks is returned unchanged.
Test plan
New cases in
withHtml.spec.js:<p>first\r\nsecond words</p>and<p>first\nsecond</p>keep the space,<p><span>first</span>\r\n<span>second</span></p>serializes tofirst second,<p>first<br>\r\nsecond</p>givesfirst\nsecondwithout a leading space,<body>\r\n<p>one</p>\r\n<p>two\r\n</p>\r\n</body>serializes toone\n\ntwo(Extra whitespace and line breaks being inserted on paste in Windows. #7364 regression guard, it also passes onmain),<pre><code>keeps its line breaks.The cases for words, inline elements and code blocks fail on
mainand pass with this change. The<br>and #7364 cases pass on both and guard against regressions.eslintandprettier --checkpass on the changed files.I also checked it in a real browser: with decap-cms-app 3.18.0 and this change applied to
decap-cms-widget-markdown, pasting<p>… rozhodujících\r\nchvílích …</p>viainsertFromPastegivesrozhodujících chvílíchinstead ofrozhodujícíchchvílích, and the result is otherwise identical tomain(no extra lines).Confirmed with a real copy and paste from Microsoft Word, see #8094 (comment).
Checklist
Please add a
xinside each checkbox: