diff options
-rw-r--r-- | Code.php | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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 { |