Editor: trim footnote anchors from post excerpts.

Adds the `excerpt_remove_footnotes` function to trim footnote anchors from post excerpts.

Props: ramonopoly, costdev, mukesh27, mcsf, azaozz.
Fixes #58805.


git-svn-id: https://develop.svn.wordpress.org/trunk@56244 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Isabel Brison
2023-07-17 01:45:24 +00:00
parent b4b0c03adc
commit 2beefda2c0
3 changed files with 72 additions and 0 deletions

View File

@@ -1009,6 +1009,27 @@ function excerpt_remove_blocks( $content ) {
return $output;
}
/**
* Parses footnotes markup out of a content string,
* and renders those appropriate for the excerpt.
*
* @since 6.3.0
*
* @param string $content The content to parse.
* @return string The parsed and filtered content.
*/
function excerpt_remove_footnotes( $content ) {
if ( ! str_contains( $content, 'data-fn=' ) ) {
return $content;
}
return preg_replace(
'_<sup data-fn="[^"]+" class="[^"]+">\s*<a href="[^"]+" id="[^"]+">\d+</a>\s*</sup>_',
'',
$content
);
}
/**
* Renders inner blocks from the allowed wrapper blocks
* for generating an excerpt.