Skip to content

Commit

Permalink
Wrap tables in handbooks with block markup
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwoodnz committed Oct 9, 2023
1 parent 5a993ba commit 8c57dfd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions source/wp-content/themes/wporg-developer-2023/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
add_filter( 'next_post_link', __NAMESPACE__ . '\get_adjacent_handbook_post_link', 10, 5 );
add_filter( 'previous_post_link', __NAMESPACE__ . '\get_adjacent_handbook_post_link', 10, 5 );
add_filter( 'get_the_archive_title_prefix', __NAMESPACE__ . '\get_reference_since_title_prefix' );
add_filter( 'the_content', __NAMESPACE__ . '\filter_standards_content' );

// Priority must be lower than 5 to precede table of contents filter.
// See: https://github.com/WordPress/wporg-mu-plugins/blob/3867a4ff6fa81de5f1e2e7b1ed4b123e4b4915b3/mu-plugins/blocks/table-of-contents/index.php#L94
Expand Down Expand Up @@ -591,6 +592,33 @@ function filter_code_content( $content ) {
);
}

/**
* Filters content for the github handbooks to wrap tables with block markup for styles.
*
* @param string $content
* @return string
*/
function filter_standards_content( $content ) {
global $post;

$post_type = get_post_type();

if ( 'blocks-handbook' !== $post_type ) {
return $content;
}

// Find table elements in the content and wrap with figure.wp-block-table
$content = preg_replace_callback(
'!<table.*?</table>!is',
function( $matches ) {
return '<figure class="wp-block-table is-style-stripes">' . $matches[0] . '</figure>';
},
$content
);

return $content;
}


/**
* Filters content for the command content blocks so Table of Contents can be added.
Expand Down

0 comments on commit 8c57dfd

Please sign in to comment.