summaryrefslogtreecommitdiff
path: root/Code.php
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2022-12-03 08:15:45 +0100
committerMartin Fischer <martin@push-f.com>2022-12-03 08:30:33 +0100
commitde6badb52bd58154baad30a73ec16e129d738fc2 (patch)
treeb28819600e1635b7cc3eba7be551745061a70e0c /Code.php
parentb4ac728a4adf513f69617b80b52284ba10e2ddf8 (diff)
refactor so that next commit has a cleaner diff
Diffstat (limited to 'Code.php')
-rw-r--r--Code.php20
1 files changed, 11 insertions, 9 deletions
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 {