Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 8, 2018
1 parent 6a54e94 commit fedb8d0
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 37 deletions.
21 changes: 10 additions & 11 deletions blocks/api/raw-handling/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,18 @@ import shortcodeConverter from './shortcode-converter';
/**
* Converts an HTML string to known blocks. Strips everything else.
*
* @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.allowIframes] Whether or not to allow iframes.
* @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 to user can use unfiltered HTML.
*
* @return {Array|string} A list of blocks or a string, depending on `handlerMode`.
*/
export default function rawHandler( { HTML, plainText = '', mode = 'AUTO', tagName, allowIframes = false } ) {
export default function rawHandler( { HTML, plainText = '', mode = 'AUTO', tagName, canUserUseUnfilteredHTML = false } ) {
// First of all, strip any meta tags.
HTML = HTML.replace( /<meta[^>]+>/, '' );

Expand Down Expand Up @@ -121,7 +120,7 @@ export default function rawHandler( { HTML, plainText = '', mode = 'AUTO', tagNa
formattingTransformer,
stripAttributes,
commentRemover,
! allowIframes && createUnwrapper( ( element ) => element.nodeName === 'IFRAME' ),
! canUserUseUnfilteredHTML && createUnwrapper( ( element ) => element.nodeName === 'IFRAME' ),
embeddedContentReducer,
createUnwrapper( isNotWhitelisted ),
blockquoteNormaliser,
Expand Down
12 changes: 12 additions & 0 deletions blocks/api/raw-handling/test/embedded-content-corrector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Internal dependencies
*/
import embeddedContentReducer from '../embedded-content-reducer';
import { deepFilterHTML } from '../utils';

describe( 'embeddedContentReducer', () => {
it( 'should move embedded content from paragraph', () => {
expect( deepFilterHTML( '<p><strong>test<img class="one"></strong><img class="two"></p>', [ embeddedContentReducer ] ) )
.toEqual( '<img class="one"><img class="two"><p><strong>test</strong></p>' );
} );
} );
19 changes: 0 additions & 19 deletions blocks/api/raw-handling/test/inline-block-corrector.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe src="https://www.google.com/maps/embed" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:html -->
<iframe src="https://www.google.com/maps/embed" width="600" height="450" allowfullscreen=""></iframe>
<!-- /wp:html -->
3 changes: 2 additions & 1 deletion blocks/api/raw-handling/test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const types = [
'ms-word',
'ms-word-online',
'evernote',
'iframe-embed',
];

describe( 'raw handling: integration', () => {
Expand All @@ -32,7 +33,7 @@ describe( 'raw handling: integration', () => {
it( type, () => {
const input = fs.readFileSync( path.join( __dirname, `${ type }-in.html` ), 'utf8' ).trim();
const output = fs.readFileSync( path.join( __dirname, `${ type }-out.html` ), 'utf8' ).trim();
const converted = rawHandler( { HTML: input } );
const converted = rawHandler( { HTML: input, canUserUseUnfilteredHTML: true } );
const serialized = typeof converted === 'string' ? converted : serialize( converted );

equal( output, serialized );
Expand Down
8 changes: 4 additions & 4 deletions blocks/api/raw-handling/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const whitelist = {
};

export function isWhitelisted( element ) {
return !! whitelist.hasOwnProperty( element.nodeName.toLowerCase() );
return whitelist.hasOwnProperty( element.nodeName.toLowerCase() );
}

export function isNotWhitelisted( element ) {
Expand Down Expand Up @@ -104,7 +104,7 @@ function isInlineForTag( nodeName, tagName ) {

export function isInline( node, tagName ) {
const nodeName = node.nodeName.toLowerCase();
return !! inlineWhitelist.hasOwnProperty( nodeName ) || isInlineForTag( nodeName, tagName );
return inlineWhitelist.hasOwnProperty( nodeName ) || isInlineForTag( nodeName, tagName );
}

export function isClassWhitelisted( tag, name ) {
Expand All @@ -125,11 +125,11 @@ export function isClassWhitelisted( tag, name ) {
* @return {boolean} True if embedded content, false if not.
*/
export function isEmbedded( node ) {
return !! embeddedWhiteList.hasOwnProperty( node.nodeName.toLowerCase() );
return embeddedWhiteList.hasOwnProperty( node.nodeName.toLowerCase() );
}

export function isInlineWrapper( node ) {
return !! inlineWrapperWhiteList.hasOwnProperty( node.nodeName.toLowerCase() );
return inlineWrapperWhiteList.hasOwnProperty( node.nodeName.toLowerCase() );
}

export function isAllowedBlock( parentNode, node ) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default class RichText extends Component {
plainText: this.pastedPlainText,
mode,
tagName: this.props.tagName,
allowIframes: this.context.canUserUseUnfilteredHTML,
canUserUseUnfilteredHTML: this.context.canUserUseUnfilteredHTML,
} );

if ( typeof content === 'string' ) {
Expand Down
2 changes: 1 addition & 1 deletion editor/components/block-settings-menu/unknown-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function UnknownConverter( { block, onReplace, small, user } ) {
onReplace( block.uid, rawHandler( {
HTML: serialize( block ),
mode: 'BLOCKS',
allowIframes: get( user, [ 'data', 'capabilities', 'unfiltered_html' ], false ),
canUserUseUnfilteredHTML: get( user, [ 'data', 'capabilities', 'unfiltered_html' ], false ),
} ) );
};

Expand Down

0 comments on commit fedb8d0

Please sign in to comment.