-
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
Add Block Transform to transform Embed blocks into Paragraph blocks. #17413
Merged
mcsf
merged 16 commits into
WordPress:master
from
desaiuditd:add/block-transform-to-transform-embed-blocks-into-paragraph-block
May 11, 2020
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f0d1f15
Add Block Transform to transform Embed blocks into Paragraph blocks.
desaiuditd 708e1c4
Fix e2e tests.
desaiuditd 60a3ce4
Update block-transforms snapshot.
desaiuditd 69f6926
Fix e2e tests.
desaiuditd 2fa4e1b
Merge branch 'master' into add/block-transform-to-transform-embed-blo…
desaiuditd bef557a
Merge branch 'master' into add/block-transform-to-transform-embed-blo…
desaiuditd 7a00726
Merge branch 'master' into add/block-transform-to-transform-embed-blo…
desaiuditd 6d88232
Add from transform for paragraph block and remove paste handler for e…
desaiuditd 5e3eaba
Fix embed transforms for default embed as well.
desaiuditd 2aa5ec5
Remove irrelevant tests.
desaiuditd 5adc5f4
Revert "Remove irrelevant tests."
desaiuditd 2b22121
Revert changes to handle embeds smartly.
desaiuditd 2e838d9
Merge branch 'master' into add/block-transform-to-transform-embed-blo…
desaiuditd 1f54392
Merge branch 'master' into add/block-transform-to-transform-embed-blo…
desaiuditd f8ecaa9
Rever core embed transformations.
desaiuditd 81d4f4c
Remove DRY and keep the logic inline.
desaiuditd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { renderToString } from '@wordpress/element'; | ||
import { createBlock } from '@wordpress/blocks'; | ||
|
||
/** | ||
* Default transforms for generic embeds. | ||
*/ | ||
const transforms = { | ||
from: [ | ||
{ | ||
type: 'raw', | ||
isMatch: ( node ) => | ||
node.nodeName === 'P' && | ||
/^\s*(https?:\/\/\S+)\s*$/i.test( node.textContent ), | ||
transform: ( node ) => { | ||
return createBlock( 'core/embed', { | ||
url: node.textContent.trim(), | ||
} ); | ||
}, | ||
}, | ||
], | ||
to: [ | ||
{ | ||
type: 'block', | ||
blocks: [ 'core/paragraph' ], | ||
transform: ( { url, caption } ) => { | ||
const link = <a href={ url }>{ caption || url }</a>; | ||
return createBlock( 'core/paragraph', { | ||
content: renderToString( link ), | ||
} ); | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
export default transforms; |
This file contains 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
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.
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.
Why not write the html as a string?
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 don't mind the added peace of mind of running this through the element serialiser. Do you have drawbacks in mind?