Topic on Extension talk:SyntaxHighlight

Dirty Hack to get it work on Windows

5
153.100.131.97 (talkcontribs)

Since passing parameters and results to the pygmentizer through stdin/stdout does not work on Windows,

i tried to use files for input and output. Pleas adjust the temporary directory to your environment.

Works for me on MediaWiki 1.33.


Greetings,

Ralf Naujokat

function ( $oldValue, &$ttl ) use ( $code, $lexer, $options, &$error ) {
	$optionPairs = [];
	foreach ( $options as $k => $v ) {
		$optionPairs[] = "{$k}={$v}";
	}
	
	$tmp = tempnam( 'D:\\MediaWiki\\tmp', 'SH' );
	$tmp_out = $tmp . ".out";
	$tmp_in  = $tmp . ".in";
	file_put_contents( $tmp_in, $code );
	
	$result = Shell::command(
		self::getPygmentizePath() .
		' -l ' . $lexer .
		' -f ' . 'html' .
		' -O ' . implode( ',', $optionPairs ) . 
		' -o ' . $tmp_out . 
		' '    . $tmp_in 
	)
		// ->input( $code )
		->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )
		->execute();

	if ( $result->getExitCode() != 0 ) {
		$ttl = WANObjectCache::TTL_UNCACHEABLE;
		$error = $result->getStderr();
		return null;
	}

	$out = file_get_contents( $tmp_out );
	
	unlink( $tmp );
	unlink( $tmp_in );
	unlink( $tmp_out );
	
	return $out;
}


153.100.131.97 (talkcontribs)

Oops, forgot to mention:

Modify the file 'includes\SyntaxHighlight.php', starting at line 305


5.148.147.130 (talkcontribs)

Thank you so much for sharing this - I was ripping my hair out!

94.124.185.2 (talkcontribs)

Also thank you, but have you get syntax highlighter working when attribute highlight is used (highlight="1,5,6" for example)?

Escalatr (talkcontribs)

I´ve tried with MediaWiki 1.35.3, but the tmp.out files are not created for the results, thus not working so far.

Reply to "Dirty Hack to get it work on Windows"