Skip to content

Commit

Permalink
fix(core): 🐛 stricter match for title parenthesis
Browse files Browse the repository at this point in the history
* Only match the parenthesis at the end of the title
* Only match when a whitespace is before the opening parenthesis
  • Loading branch information
alistair3149 committed May 1, 2024
1 parent 71ef6b7 commit 0015743
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions includes/Partials/PageTitle.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ final class PageTitle extends Partial {
/**
* Wrap text within parenthesis with a span tag
*
* @param string $data title of the page
* @param string $data HTML of the title of the page
* @return string
*/
public function decorateTitle( $data ) {
if ( $this->shouldAddParenthesis() ) {
$pattern = '/(\(.+\))/';
$replacement = '<span class="mw-page-title-parenthesis">$1</span>';
// Look for the </span> to ensure that it is the last parenthesis of the title
$pattern = '/\s(\(.+\))<\/span>/';
$replacement = ' <span class="mw-page-title-parenthesis">$1</span></span>';
return preg_replace( $pattern, $replacement, $data );
}
return $data;
Expand Down

0 comments on commit 0015743

Please sign in to comment.