Skip to content
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

Paste: remove non inline elements from inline pasted content #2855

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions blocks/api/paste/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import msListConverter from './ms-list-converter';
import listMerger from './list-merger';
import imageCorrector from './image-corrector';
import blockquoteNormaliser from './blockquote-normaliser';
import { deepFilter, isInvalidInline, isNotWhitelisted, isPlain } from './utils';
import { deepFilter, isInvalidInline, isNotWhitelisted, isPlain, isInline } from './utils';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we don't care about the order of import statements. In Calypso they introduced codemod which sorts everything for you. Just saying, no action necessary here :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I saw your ticket #2819. :)

import showdown from 'showdown';

export default function( { HTML, plainText, inline } ) {
Expand Down Expand Up @@ -50,7 +50,7 @@ export default function( { HTML, plainText, inline } ) {
formattingTransformer,
stripAttributes,
commentRemover,
createUnwrapper( isNotWhitelisted ),
createUnwrapper( ( node ) => isNotWhitelisted( node ) || ( inline && ! isInline( node ) ) ),
blockquoteNormaliser,
] );

Expand Down
9 changes: 9 additions & 0 deletions blocks/api/paste/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ describe( 'paste', () => {
equal( pastedBlock.name, 'test/unknown' );
equal( pastedBlock.attributes.content, '<figcaption>test</figcaption>' );
} );

it( 'should filter inline content', () => {
const filtered = paste( {
HTML: '<h2><em>test</em></h2>',
inline: true,
} );

equal( filtered, '<em>test</em>' );
} );
} );

import './integration';