-
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
Code block: preserve newlines #59627
Conversation
Size Change: +908 B (0%) Total Size: 1.71 MB
ℹ️ View Unchanged
|
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: @oldrup. 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. |
typeof attributes.content === 'string' | ||
? attributes.content | ||
: attributes.content.toHTMLString( { | ||
preserveWhiteSpace: true, |
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.
Doesn't preserveNewLine
make more sense?
I tested the following three plugins and they work as expected. |
@t-hamano Oh, but those two plugins that are extending the Code block shouldn't work because they're overriding the save function? 🤔 |
I investigated the implementation of three plugins. For developers who are overriding a code block's save function, should we call on them to use the new option ✅ Syntax-highlighting Code BlockThis plugin only overrides the edit component, and the save function seems to utilize the core function. https://github.com/westonruter/syntax-highlighting-code-block/blob/develop/src/index.js ✅ PrismaticAlthough it includes a custom block, this plugin does not seem to override either the edit component or the save function for the core code block. https://plugins.trac.wordpress.org/browser/prismatic/trunk/js?order=name
|
Ok that's great, I thought Syntax-highlighting Code Block just copied from the fork. In that case, yes, let's get them to fix the save function, otherwise the fix will get more complex. |
Yes, I agree with this too. |
@youknowriad As far as I've tested, this PR seems to be working correctly. I'm not confident in the points reviewed in this comment, but it may not need to be changed. We're planning to backport this PR to RC2, right? |
@t-hamano yes, that's the goal RC2 |
(The link you shared doesn't seem to work) |
Sorry, I meant the below URL |
Yes, it does seem specific to new lines (looking at the implementation), so maybe we can rename the option for now. |
@t-hamano Actually, it seems we already have |
Yes, I've seen attempts to rename this to |
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.
As mentioned in this comment, this issue has a major impact on plugins that extend code blocks and code samples on WordPress.org, so let's merge/backport this PR and test if RC1 resolves the issue.
Unlinked contributors: oldrup. Co-authored-by: ellatrix <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: timnolte <[email protected]> Co-authored-by: justintadlock <[email protected]> Co-authored-by: dmsnell <[email protected]>
I just cherry-picked this PR to the pick/wp-65-rc-2 branch to get it included in the next release: b78d306 |
Unlinked contributors: oldrup. Co-authored-by: ellatrix <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: timnolte <[email protected]> Co-authored-by: justintadlock <[email protected]> Co-authored-by: dmsnell <[email protected]>
Unlinked contributors: oldrup. Co-authored-by: ellatrix <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: youknowriad <[email protected]> Co-authored-by: timnolte <[email protected]> Co-authored-by: justintadlock <[email protected]> Co-authored-by: dmsnell <[email protected]>
What?
This PR tries to fix two problems:
Custom code blocks that are using RichText will now also serialise line breaks as HTML elements. The ones I've checked have all formatting options disabled, so they are using RichText more as a plain text editor. In this PR, I will preserve the newlines if the attribute source type is still a string andLet's handle that in a follow-up.preserveWhiteSpace
is turned on (serialisation happens in the edit function in that case). IDEALLY, these plugins either switch toPlainText
OR allow HTML inside their blocks.Why?
Fixes #59548.
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast