Skip to content

Commit

Permalink
Paste: replace iframes with url (#20983)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 19, 2020
1 parent c6d5bd5 commit f90dc20
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 68 deletions.
9 changes: 1 addition & 8 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ function RichTextWrapper(

const selectionStart = getSelectionStart();
const selectionEnd = getSelectionEnd();
const {
__experimentalCanUserUseUnfilteredHTML,
__experimentalUndo: undo,
} = getSettings();
const { __experimentalUndo: undo } = getSettings();

let isSelected;

Expand All @@ -171,7 +168,6 @@ function RichTextWrapper(
}

return {
canUserUseUnfilteredHTML: __experimentalCanUserUseUnfilteredHTML,
isCaretWithinFormattedText: isCaretWithinFormattedText(),
selectionStart: isSelected ? selectionStart.offset : undefined,
selectionEnd: isSelected ? selectionEnd.offset : undefined,
Expand All @@ -186,7 +182,6 @@ function RichTextWrapper(
// retreived from the store on merge.
// To do: fix this somehow.
const {
canUserUseUnfilteredHTML,
isCaretWithinFormattedText,
selectionStart,
selectionEnd,
Expand Down Expand Up @@ -394,7 +389,6 @@ function RichTextWrapper(
plainText,
mode,
tagName,
canUserUseUnfilteredHTML,
} );

if ( typeof content === 'string' ) {
Expand Down Expand Up @@ -437,7 +431,6 @@ function RichTextWrapper(
onSplit,
splitValue,
__unstableEmbedURLOnPaste,
canUserUseUnfilteredHTML,
multiline,
]
);
Expand Down
2 changes: 0 additions & 2 deletions packages/block-library/src/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { html as icon } from '@wordpress/icons';
import edit from './edit';
import metadata from './block.json';
import save from './save';
import transforms from './transforms';

const { name } = metadata;

Expand All @@ -34,7 +33,6 @@ export const settings = {
className: false,
html: false,
},
transforms,
edit,
save,
};
29 changes: 0 additions & 29 deletions packages/block-library/src/html/transforms.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ _Parameters_
- _options.plainText_ `[string]`: Plain text version.
- _options.mode_ `[string]`: Handle content as blocks or inline content. _ 'AUTO': Decide based on the content passed. _ 'INLINE': Always handle as inline content, and return string. \* 'BLOCKS': Always handle as blocks, and return array of blocks.
- _options.tagName_ `[Array]`: The tag into which content will be inserted.
- _options.canUserUseUnfilteredHTML_ `[boolean]`: Whether or not the user can use unfiltered HTML.

_Returns_

Expand Down
8 changes: 2 additions & 6 deletions packages/blocks/src/api/raw-handling/iframe-remover.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { remove } from '@wordpress/dom';

/**
* Removes iframes.
*
Expand All @@ -12,6 +7,7 @@ import { remove } from '@wordpress/dom';
*/
export default function( node ) {
if ( node.nodeName === 'IFRAME' ) {
remove( node );
const text = node.ownerDocument.createTextNode( node.src );
node.parentNode.replaceChild( text, node );
}
}
22 changes: 8 additions & 14 deletions packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,13 @@ function htmlToBlocks( { html, rawTransforms } ) {
* Converts an HTML string to known blocks. Strips everything else.
*
* @param {Object} options
* @param {string} [options.HTML] The HTML to convert.
* @param {string} [options.plainText] Plain text version.
* @param {string} [options.mode] Handle content as blocks or inline content.
* * 'AUTO': Decide based on the content passed.
* * 'INLINE': Always handle as inline content, and return string.
* * 'BLOCKS': Always handle as blocks, and return array of blocks.
* @param {Array} [options.tagName] The tag into which content will be inserted.
* @param {boolean} [options.canUserUseUnfilteredHTML] Whether or not the user can use unfiltered HTML.
* @param {string} [options.HTML] The HTML to convert.
* @param {string} [options.plainText] Plain text version.
* @param {string} [options.mode] Handle content as blocks or inline content.
* * 'AUTO': Decide based on the content passed.
* * 'INLINE': Always handle as inline content, and return string.
* * 'BLOCKS': Always handle as blocks, and return array of blocks.
* @param {Array} [options.tagName] The tag into which content will be inserted.
*
* @return {Array|string} A list of blocks or a string, depending on `handlerMode`.
*/
Expand All @@ -142,7 +141,6 @@ export function pasteHandler( {
plainText = '',
mode = 'AUTO',
tagName,
canUserUseUnfilteredHTML = false,
} ) {
// First of all, strip any meta tags.
HTML = HTML.replace( /<meta[^>]+>/g, '' );
Expand Down Expand Up @@ -243,15 +241,11 @@ export function pasteHandler( {
phrasingContentReducer,
specialCommentConverter,
commentRemover,
iframeRemover,
figureContentReducer,
blockquoteNormaliser,
];

if ( ! canUserUseUnfilteredHTML ) {
// Should run before `figureContentReducer`.
filters.unshift( iframeRemover );
}

const schema = {
...blockContentSchema,
// Keep top-level phrasing content, normalised by `normaliseBlocks`.
Expand Down
6 changes: 1 addition & 5 deletions test/integration/blocks-raw-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,7 @@ describe( 'Blocks raw handling', () => {
throw new Error( `Expected fixtures for type ${ type }` );
}

const converted = pasteHandler( {
HTML,
plainText,
canUserUseUnfilteredHTML: true,
} );
const converted = pasteHandler( { HTML, plainText } );
const serialized =
typeof converted === 'string'
? converted
Expand Down
8 changes: 5 additions & 3 deletions test/integration/fixtures/iframe-embed-out.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- wp:html -->
<figure><iframe src="https://www.google.com/maps/embed" width="600" height="450" allowfullscreen=""></iframe></figure>
<!-- /wp:html -->
<!-- wp:embed {"url":"https://www.google.com/maps/embed"} -->
<figure class="wp-block-embed"><div class="wp-block-embed__wrapper">
https://www.google.com/maps/embed
</div></figure>
<!-- /wp:embed -->

0 comments on commit f90dc20

Please sign in to comment.