From de6badb52bd58154baad30a73ec16e129d738fc2 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 3 Dec 2022 08:15:45 +0100 Subject: refactor so that next commit has a cleaner diff --- Code.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'Code.php') diff --git a/Code.php b/Code.php index ca02b3c..0243e6f 100644 --- a/Code.php +++ b/Code.php @@ -61,24 +61,26 @@ function renderCode( string $code, $lang, $outputPage, ?array $tagAttrs = null ) if ( ExtensionRegistry::getInstance()->isLoaded( 'SyntaxHighlight' ) ) { $result = \SyntaxHighlight::highlight( $code, $lang['pygmentsLexer'], $tagAttrs ?? [ 'line' => true ] ); if ( $result->isOk() ) { - $out = $result->getValue(); + $codeBlock = $result->getValue(); $outputPage->addModuleStyles( [ 'ext.pygments' ] ); } else { - $out = pre( $code, $tagAttrs ); + $codeBlock = pre( $code, $tagAttrs ); } } else { - $out = pre( $code, $tagAttrs ); + $codeBlock = pre( $code, $tagAttrs ); } foreach ( $lang['linkifiers'] as $regex => $href ) { - $out = preg_replace_callback( $regex, fn( $match ) => + $codeBlock = preg_replace_callback( $regex, fn( $match ) => Xml::element( 'a', [ 'href' => str_replace( '$1', $match[0], $href ), 'tabindex' => -1 ], $match[0] ), - $out ); + $codeBlock ); } + $actions = ''; + foreach ( $lang['actions'] as $action => $url ) { if ( str_contains( $url, '$url' ) ) { // FUTURE: it would be nice to still display such actions for code pages @@ -89,12 +91,12 @@ function renderCode( string $code, $lang, $outputPage, ?array $tagAttrs = null ) // The wfMessage allows admins to create MediaWiki:codeaction-label with a template call // if they want to enable their users to customize or localize the code action labels. - $out .= Xml::openElement( 'a', [ 'href' => str_replace( '$code', $encodedCode, $url ) ] ); - $out .= wfMessage( "codeaction-label", $action )->parse(); - $out .= Xml::closeElement( 'a' ) . ' '; + $actions .= Xml::openElement( 'a', [ 'href' => str_replace( '$code', $encodedCode, $url ) ] ); + $actions .= wfMessage( "codeaction-label", $action )->parse(); + $actions .= Xml::closeElement( 'a' ) . ' '; } - return $out; + return $codeBlock . $actions; } class ContentHandler extends TextContentHandler { -- cgit v1.2.3