Skip to content

Commit

Permalink
Trim footnote anchors from excerpts (#52518)
Browse files Browse the repository at this point in the history
* Trim footnote anchors from excerpts

* Add comments, fix spacing, appease linter
  • Loading branch information
mcsf authored and ockham committed Jul 12, 2023
1 parent 6fe2c96 commit 0c1a9c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/compat/wordpress-6.3/footnotes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Compatiblity filters for improved footnotes support.
*
* In core, this could be fixed directly in key functions.
*
* @package gutenberg
*/

/**
* Trims footnote anchors from content.
*
* @param string $content HTML content.
* @return string Filtered content.
*/
function gutenberg_trim_footnotes( $content ) {
if ( ! doing_filter( 'get_the_excerpt' ) ) {
return $content;
}

static $footnote_pattern = '_<sup data-fn="[^"]+" class="[^"]+">\s*<a href="[^"]+" id="[^"]+">\d+</a>\s*</sup>_';
return preg_replace( $footnote_pattern, '', $content );
}

add_filter( 'the_content', 'gutenberg_trim_footnotes' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require_once __DIR__ . '/compat/wordpress-6.3/link-template.php';
require_once __DIR__ . '/compat/wordpress-6.3/block-patterns.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-blocks-controller.php';
require_once __DIR__ . '/compat/wordpress-6.3/footnotes.php';

// Experimental.
if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) {
Expand Down

1 comment on commit 0c1a9c6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 0c1a9c6.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5533773848
📝 Reported issues:

Please sign in to comment.