diff options
author | Martin Fischer <martin@push-f.com> | 2022-12-03 08:15:45 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-12-03 08:30:33 +0100 |
commit | de6badb52bd58154baad30a73ec16e129d738fc2 (patch) | |
tree | b28819600e1635b7cc3eba7be551745061a70e0c /Code.php | |
parent | b4ac728a4adf513f69617b80b52284ba10e2ddf8 (diff) |
refactor so that next commit has a cleaner diff
Diffstat (limited to 'Code.php')
-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 { |