Skip to content

Commit

Permalink
Content parser: Parse out the href from the Link Wrapper block
Browse files Browse the repository at this point in the history
The link destination of this block should be translatable.

See #446 (comment)
  • Loading branch information
ryelle committed Jun 3, 2024
1 parent 38790bc commit d14d5a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion env/export-content/includes/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function __construct( string $content = '' ) {
// Generic shortcode handler.
'core/shortcode' => new Parsers\ShortcodeBlock(),

'core/spacer' => new Parsers\Noop(),
// These contain other blocks to be parsed.
'core/column' => new Parsers\Noop(),
'core/columns' => new Parsers\Noop(),
Expand All @@ -47,8 +46,14 @@ public function __construct( string $content = '' ) {
'core/code' => new Parsers\Noop(),
'core/embed' => new Parsers\Noop(),

// No content.
'core/spacer' => new Parsers\Noop(),

// Common core blocks that use the default parser.
'core/media-text' => new Parsers\BasicText(),

// Shared custom blocks.
'wporg/link-wrapper' => new Parsers\HTMLParser( 'a', [ 'href' ] ),
];
}

Expand Down
5 changes: 5 additions & 0 deletions env/export-content/tests/block-parser-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public function data_block_content_i18n() {
"<!-- wp:table -->\n<figure class=\"wp-block-table\"><table><thead><tr><th>Cookie</th><th>Logged-in Users Only?</th></tr></thead><tbody><tr><th>welcome-{blog_id}</th><td>No</td></tr><tr><th>showComments</th><td>No</td></tr></tbody></table></figure>\n<!-- /wp:table -->",
"<!-- wp:table -->\n<figure class=\"wp-block-table\"><table><thead><tr><th><?php _e( 'Cookie', 'wporg' ); ?></th><th><?php _e( 'Logged-in Users Only?', 'wporg' ); ?></th></tr></thead><tbody><tr><th><?php _e( 'welcome-{blog_id}', 'wporg' ); ?></th><td><?php _e( 'No', 'wporg' ); ?></td></tr><tr><th><?php _e( 'showComments', 'wporg' ); ?></th><td><?php _e( 'No', 'wporg' ); ?></td></tr></tbody></table></figure>\n<!-- /wp:table -->",
],
[
// Link Wrapper block with child content.
'<!-- wp:wporg/link-wrapper {"align":"full"} --><a class="wp-block-wporg-link-wrapper alignfull" href="https://wordpress.org/news/2024/05/wordcamp-europe-2024-mid-year-update-and-qa-with-matt-mullenweg/"><!-- wp:paragraph --><p>Matt Mullenweg at WordCamp Europe—streaming live June 15</p><!-- /wp:paragraph --></a><!-- /wp:wporg/link-wrapper -->',
'<!-- wp:wporg/link-wrapper {"align":"full"} --><a class="wp-block-wporg-link-wrapper alignfull" href="<?php _e( \'https://wordpress.org/news/2024/05/wordcamp-europe-2024-mid-year-update-and-qa-with-matt-mullenweg/\', \'wporg\' ); ?>"><!-- wp:paragraph --><p><?php _e( \'Matt Mullenweg at WordCamp Europe—streaming live June 15\', \'wporg\' ); ?></p><!-- /wp:paragraph --></a><!-- /wp:wporg/link-wrapper -->',
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,49 @@

<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|10"}},"className":"is-style-cards-grid","layout":{"type":"grid","minimumColumnWidth":"32%"}} -->
<div class="wp-block-group is-style-cards-grid"><!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/squarespace-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/squarespace-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Squarespace to WordPress</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/tumblr-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/tumblr-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Tumblr to WordPress</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/html-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/html-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( 'HTML to WordPress', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/rss-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/rss-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( 'RSS to WordPress', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/wix-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/wix-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Wix to WordPress</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/drupal-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/drupal-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Drupal to WordPress</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/blogger-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/blogger-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( 'Blogger to WordPress', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/blob/trunk/guides/wordpress-to-wordpress.md"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/blob/trunk/guides/wordpress-to-wordpress.md', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( 'WordPress to WordPress', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper --></div>
Expand All @@ -112,19 +112,19 @@

<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|10"}},"className":"is-style-cards-grid","layout":{"type":"grid","minimumColumnWidth":"32%"}} -->
<div class="wp-block-group is-style-cards-grid"><!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/tree/trunk/tools/figma-to-blocks"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/tree/trunk/tools/figma-to-blocks', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Figma to Blocks</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/tree/trunk/tools/divi-to-gutenberg"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/tree/trunk/tools/divi-to-gutenberg', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Divi to Blocks</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper -->

<!-- wp:wporg/link-wrapper -->
<a class="wp-block-wporg-link-wrapper" href="https://github.com/WordPress/move-to-wp/tree/trunk/tools/classic-to-gutenberg"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<a class="wp-block-wporg-link-wrapper" href="<?php _e( 'https://github.com/WordPress/move-to-wp/tree/trunk/tools/classic-to-gutenberg', 'wporg' ); ?>"><!-- wp:heading {"level":3,"style":{"spacing":{"margin":{"top":"0","bottom":"0"}},"typography":{"fontStyle":"normal","fontWeight":"700"}},"fontSize":"small","fontFamily":"inter"} -->
<h3 class="wp-block-heading has-inter-font-family has-small-font-size" style="margin-top:0;margin-bottom:0;font-style:normal;font-weight:700"><?php _e( '<strong>Classic Editor to Blocks</strong>', 'wporg' ); ?></h3>
<!-- /wp:heading --></a>
<!-- /wp:wporg/link-wrapper --></div>
Expand Down

0 comments on commit d14d5a2

Please sign in to comment.