From 0cc844434abfc7fd19cd98551a5b60e9898cb08e Mon Sep 17 00:00:00 2001 From: iseulde Date: Mon, 2 Oct 2017 14:43:42 +0200 Subject: [PATCH] Paste: remove non inline elements from inline pasted content --- blocks/api/paste/index.js | 4 ++-- blocks/api/paste/test/index.js | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/blocks/api/paste/index.js b/blocks/api/paste/index.js index 697a963c828b7a..a8721465f1edf5 100644 --- a/blocks/api/paste/index.js +++ b/blocks/api/paste/index.js @@ -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'; import showdown from 'showdown'; export default function( { HTML, plainText, inline } ) { @@ -50,7 +50,7 @@ export default function( { HTML, plainText, inline } ) { formattingTransformer, stripAttributes, commentRemover, - createUnwrapper( isNotWhitelisted ), + createUnwrapper( ( node ) => isNotWhitelisted( node ) || ( inline && ! isInline( node ) ) ), blockquoteNormaliser, ] ); diff --git a/blocks/api/paste/test/index.js b/blocks/api/paste/test/index.js index 6f7d1e53f9588a..2eacda7a389d8e 100644 --- a/blocks/api/paste/test/index.js +++ b/blocks/api/paste/test/index.js @@ -68,6 +68,15 @@ describe( 'paste', () => { equal( pastedBlock.name, 'test/unknown' ); equal( pastedBlock.attributes.content, '
test
' ); } ); + + it( 'should filter inline content', () => { + const filtered = paste( { + HTML: '

test

', + inline: true, + } ); + + equal( filtered, 'test' ); + } ); } ); import './integration';