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
Raw handling: preserve empty paragraphs #59476
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @designsimply, @AdrienM76, @housebolt, @u451f, @selimanac, @zackkatz, @vrrobz, @XavDeb-duplicate, @mlaetitia, @petralian, @marcuswisecaesar, @selectedselections, @Studio28, @nboot8, @eoinsav, @jq-87, @eyyddxx04, @AlphaOmega5732, @Blogography. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +5.96 kB (0%) Total Size: 1.72 MB
ℹ️ View Unchanged
|
node.parentNode.nodeName !== 'P' || | ||
node.parentNode.childNodes.length === 1 | ||
) { | ||
if ( ! node.parentNode || node.parentNode.nodeName !== 'P' ) { |
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.
@ellatrix: can you explain this change? The code no longer matches the comment. If you can confirm my intuition here:
- Now the
else
branch will be run whenever the comment node's parent is a paragraph, even if it only has one child (the comment node). - This forces all paragraphs through the
paragraphBuilder
walk, ensuring that paragraphs that only contained the comment (and would become<p></p>
) are destroyed.
If the above is right, some follow-up questions:
- Is it necessary to the current PR, or an adjacent change?
- Looking at the tests in
packages/blocks/src/api/raw-handling/test/special-comment-converter.js
, there is now some inconsistency between the handling of<!--more-->
and<!--nextpage-->
— with the latter, tests still expect empty paragraph nodes to be produced. Should we fix that?
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.
Not adjacent, it was required to update this because some of the integration tests started failing with extra empty paragraphs that the original change was no longer removing.
I didn't think the comment no longer matched, but I reworded it.
I also fixed it for next 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.
Looks good, and I approved it so I can get out of your way :), but I left a suggestion I think you should follow.
@@ -105,7 +67,35 @@ function moreCommentConverter( node, doc ) { | |||
} | |||
} | |||
|
|||
function createMore( customText, noTeaser, doc ) { | |||
function createBlock( commentNode, doc ) { |
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 understand the convenience of folding everything into a single function. However, the resulting function is more difficult to understand for someone who doesn't have our context. Can we add a comment explaining that this function handles both more
and nextpage
comments, for ease of maintenance?
If we wanted to go the extra mile, we could even make that explicit in code, either with a switch:
switch ( commentNode.nodeValue.match(/\w+/)?.[0] ) {
case 'nextpage':
// do stuff
break;
case 'more':
// do stuff
break;
}
Or simply via function delegation:
function createBlock( commentNode, doc ) {
if ( commentNode.nodeValue === 'nextpage' ) {
return createNextPage( doc );
}
return createMore( commentNode, doc );
}
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.
Restored the original functions :)
Unlinked contributors: designsimply, AdrienM76, housebolt, u451f, selimanac, zackkatz, vrrobz, XavDeb-duplicate, mlaetitia, petralian, marcuswisecaesar, selectedselections, Studio28, nboot8, eoinsav, jq-87, eyyddxx04, AlphaOmega5732, Blogography. Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: mcsf <mcsf@git.wordpress.org> Co-authored-by: earnjam <earnjam@git.wordpress.org> Co-authored-by: mrwweb <mrwweb@git.wordpress.org> Co-authored-by: timnicholson <timnicholson@git.wordpress.org> Co-authored-by: TiBiker <steveblum@git.wordpress.org> Co-authored-by: QuietNoise <quietnoise@git.wordpress.org> Co-authored-by: rodrigo-arias <kreppar@git.wordpress.org> Co-authored-by: paaljoachim <paaljoachim@git.wordpress.org> Co-authored-by: YukinobuAsakawa <yukinobu@git.wordpress.org>
What?
Fixes #11211.
For raw handling (not paste!) we should preserve the original content as much as possible. That means also preserving empty or empty looking paragraphs.
Why?
The philosophy of raw handling, as opposed to paste, is to preserve as much legacy content as possible while also converting to blocks.
How?
Pass a flag. We also need to strip the paragraphs around short codes and handle special comments better.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast