-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add block transform to transform preformatted block into code block #22634
Conversation
Size Change: +15 B (0%) Total Size: 1.12 MB
ℹ️ View Unchanged
|
378a6ec
to
d9dffdc
Compare
{ | ||
type: 'block', | ||
blocks: [ 'core/code' ], | ||
transform: ( attributes ) => createBlock( 'core/code', attributes ), |
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 noticed that the "preformatted" content attribute has this property on it "__unstablePreserveWhiteSpace": true
I wonder if that means that we should sanitize the content when transforming cc @ellatrix
Also, do we want to support the opposite direction too?
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.
Also, do we want to support the opposite direction too?
Yes, but this is already implemented, see my gif in the Screenshot section.
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 it's fine, because a textarea
doesn't need anything special to preserve whitespace.
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.
And I believe we use characters for line breaks when __unstablePreserveWhiteSpace
is enabled, so I don't think there's any HTML to strip. Worth noting that pre
can contain HTML though. Can have bold, links etc.
Description
This provides a block transform to transform Preformatted into Code.
How has this been tested?
Add a preformatted block, insert some content, convert to code block, ensure that the content is still there. Bonus: Convert back to preformatted and code is still there.
Screenshots
Types of changes
New feature
Checklist: