Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions packages/block-library/src/embed/transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { createBlock } from '@wordpress/blocks';
import { isURL, getFilename } from '@wordpress/url';

/**
* Internal dependencies
Expand All @@ -22,10 +23,22 @@ const transforms = {
from: [
{
type: 'raw',
isMatch: ( node ) =>
node.nodeName === 'P' &&
/^\s*(https?:\/\/\S+)\s*$/i.test( node.textContent ) &&
node.textContent?.match( /https/gi )?.length === 1,
isMatch: ( node ) => {
if ( node.nodeName !== 'P' ) {
return false;
}
const trimmed = node.textContent.trim();
if (
! isURL( trimmed ) ||
! /^https:\/\//i.test( trimmed ) ||
trimmed.match( /https:\/\//gi )?.length !== 1
) {
return false;
}
// Reject URLs whose pathname ends in a file extension.
// Embed providers don't use such URLs
return ! /\.[a-z0-9]+$/i.test( getFilename( trimmed ) );
Comment thread
Mamaduka marked this conversation as resolved.
Resolved
},
transform: ( node ) => {
const url = rewriteXToTwitter( node.textContent.trim() );
return createBlock( EMBED_BLOCK, {
Expand Down
Loading