Skip to content

Commit

Permalink
Add more paste matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jul 1, 2017
1 parent 9f3ecef commit 7c066a2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ registerBlockType( 'core/heading', {
} );
},
},
{
type: 'raw',
matcher: ( node ) => /H\d/.test( node.nodeName ),
attributes: {
content: children( 'h1,h2,h3,h4,h5,h6' ),
nodeName: prop( 'h1,h2,h3,h4,h5,h6', 'nodeName' ),
},
},
],
to: [
{
Expand Down
17 changes: 17 additions & 0 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ registerBlockType( 'core/image', {
caption: children( 'figcaption' ),
},

transforms: {
from: [
{
type: 'raw',
matcher: ( node ) => (
node.nodeName === 'IMG' ||
( ! node.textContent && node.querySelector( 'img' ) )
),
attributes: {
url: attr( 'img', 'src' ),
alt: attr( 'img', 'alt' ),
caption: children( 'figcaption' ),
},
},
],
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) {
Expand Down
9 changes: 8 additions & 1 deletion blocks/library/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ registerBlockType( 'core/list', {
} );
},
},

{
type: 'raw',
matcher: ( node ) => node.nodeName === 'OL' || node.nodeName === 'UL',
attributes: {
nodeName: prop( 'ol,ul', 'nodeName' ),
values: children( 'ol,ul' ),
},
},
],
to: [
{
Expand Down
6 changes: 5 additions & 1 deletion blocks/library/text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ registerBlockType( 'core/text', {
from: [
{
type: 'raw',
matcher: ( node ) => node.nodeName === 'P',
matcher: ( node ) => (
node.nodeName === 'P' &&
// Do not allow embedded content.
! node.querySelector( 'audio, canvas, embed, iframe, img, math, object, svg, video' )
),
attributes: {
content: query( 'p', children() ),
},
Expand Down

0 comments on commit 7c066a2

Please sign in to comment.