Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 11 additions & 11 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function parseWithTinyMCE( content ) {
// In : <!-- wp:core/embed url:youtube.com/xxx& -->
// Out : <wp-block slug="core/embed" attributes="url:youtube.com/xxx&amp;">
content = content.replace(
/<!--\s*(\/?)wp:([a-z0-9/-]+)((?:\s+[a-z0-9_-]+:[^\s]+)*)\s*-->/g,
/<!--\s*(\/?)wp:([a-z0-9/-]+)((?:\s+[a-z0-9_-]+="[^"]*")*)\s*-->/g,
function( match, closingSlash, slug, attributes ) {
if ( closingSlash ) {
return '</wp-block>';
Expand Down Expand Up @@ -166,15 +166,15 @@ export function parseWithTinyMCE( content ) {
}, {} );

// Retrieve the block attributes from the original delimiters
const blockAttributes = unescape( nodeAttributes.attributes || '' )
.split( /\s+/ )
.reduce( ( memo, attrString ) => {
const pieces = attrString.match( /^([a-z0-9_-]+):(.*)$/ );
if ( pieces ) {
memo[ pieces[ 1 ] ] = pieces[ 2 ];
}
return memo;
}, {} );
const attributesMatcher = /([a-z0-9_-]+)="([^"]*)"/g;
const blockAttributes = {};
let match;
do {
match = attributesMatcher.exec( unescape( nodeAttributes.attributes || '' ) );
if ( match ) {
blockAttributes[ match[ 1 ] ] = match[ 2 ];
}
} while ( !! match );

// Try to create the block
const block = createBlockWithFallback(
Expand Down Expand Up @@ -221,4 +221,4 @@ export function parseWithGrammar( content ) {
}, [] );
}

export default parseWithTinyMCE;
export default parseWithGrammar;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't matter either way, but is this change intentional?

Separately, it might be nice to run the CI build against both parsers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not intentional, I was switching to try both.

4 changes: 2 additions & 2 deletions blocks/api/post.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ WP_Block_Attribute_List
}, {} ) }

WP_Block_Attribute
= name:WP_Block_Attribute_Name ":" value:WP_Block_Attribute_Value
= name:WP_Block_Attribute_Name '="' value:WP_Block_Attribute_Value '"'
{ return { name: name, value: value }; }

WP_Block_Attribute_Name
Expand All @@ -68,7 +68,7 @@ ASCII_AlphaNumeric
/ Special_Chars

WP_Block_Attribute_Value_Char
= [^ \t\r\n]
= [^"]

ASCII_Letter
= [a-zA-Z]
Expand Down
3 changes: 2 additions & 1 deletion blocks/api/test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe( 'block parser', () => {
} );

const parsed = parse(
'<!-- wp:core/test-block smoked:yes -->' +
'<!-- wp:core/test-block smoked="yes" url="http://google.com" -->' +
Copy link
Member

Choose a reason for hiding this comment

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

What does this new url attribute add? Let's have a test for spaces and some special characters like '& instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, handling spaces and special chars like these is one of the reasons I made this switch

'Brisket' +
'<!-- /wp:core/test-block -->'
);
Expand All @@ -160,6 +160,7 @@ describe( 'block parser', () => {
expect( parsed[ 0 ].attributes ).to.eql( {
content: 'Brisket',
smoked: 'yes',
url: 'http://google.com'
} );
expect( parsed[ 0 ].uid ).to.be.a( 'string' );
} );
Expand Down
2 changes: 1 addition & 1 deletion post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ window._wpGutenbergPost = {
'<ul><li>Ship early</li><li>Ship often</li><li>Listen to feedback from real people</li><li>Anticipate market direction</li></ul>',
'<!-- /wp:core/list -->',

'<!-- wp:core/embed url:https://www.youtube.com/watch?v=Nl6U7UotA-M -->',
'<!-- wp:core/embed url="https://www.youtube.com/watch?v=Nl6U7UotA-M" -->',
'<iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe>',
'<!-- /wp:core/embed -->',
].join( '' ),
Expand Down