diff --git a/includes/SyntaxHighlight.php b/includes/SyntaxHighlight.php index 93f0a09f..fd7354b3 100644 --- a/includes/SyntaxHighlight.php +++ b/includes/SyntaxHighlight.php @@ -172,11 +172,6 @@ class SyntaxHighlight extends ExtensionTagHandler { // Replace strip markers (For e.g. {{#tag:syntaxhighlight|...}}) $out = $parser->getStripState()->unstripNoWiki( $text ?? '' ); - if ( !$parser->incrementExpensiveFunctionCount() ) { - // Highlighting is expensive, return unstyled - return self::plainCodeWrap( $out, isset( $args['inline'] ) ); - } - $result = self::processContent( $out, $args, $parser ); foreach ( $result['cats'] as $cat ) { $parser->addTrackingCategory( $cat ); @@ -242,9 +237,10 @@ class SyntaxHighlight extends ExtensionTagHandler { * @param string $code * @param string|null $lang * @param array $args + * @param Parser|null $parser Parser, if generating content to be parsed. * @return Status */ - private static function highlightInner( $code, $lang = null, $args = [] ) { + private static function highlightInner( $code, $lang = null, $args = [], ?Parser $parser = null ) { $status = new Status; $lexer = self::getLexer( $lang ); @@ -282,6 +278,12 @@ class SyntaxHighlight extends ExtensionTagHandler { return $status; } + if ( $parser && !$parser->incrementExpensiveFunctionCount() ) { + // Highlighting is expensive, return unstyled + $status->value = self::plainCodeWrap( $code, $isInline ); + return $status; + } + $options = [ 'cssclass' => self::HIGHLIGHT_CSS_CLASS, 'encoding' => 'utf-8', @@ -372,7 +374,7 @@ class SyntaxHighlight extends ExtensionTagHandler { * code as its value. */ public static function highlight( $code, $lang = null, $args = [], ?Parser $parser = null ) { - $status = self::highlightInner( $code, $lang, $args ); + $status = self::highlightInner( $code, $lang, $args, $parser ); $output = $status->getValue(); $isInline = isset( $args['inline'] );