Open main menu

Extension talk:SyntaxHighlight

About this board


Previous discussion was archived at Extension talk:SyntaxHighlight/Archive 2017 on 2017-03-29.

Syntax highlighting does not work

Zewas (talkcontribs)

I'm using MediaWiki 1.28.2 and SyntaxHighlight 2.0. My system is a 64 bit Windows 10 machine.

The code ends up in a plain PRE tag and the page is added to category "Pages with syntax highlighting errors". Setting $wgShowExceptionDetails did not trigger any output. On a hunch I renamed pygmentize to pygmentize.exe, tried to run it via the command line and got this error message:

Unsupported 16-Bit Application

The program or feature "\\...\pygmentize.exe" cannot start or run due to incompatibility with 64-bit versions of Windows. Please contact the software vendor to ask if a 64-bit Windows compatible version is available.

Is that the problem? Do I need a different version of pygmentize? Where do I get that?

Lanthanis (talkcontribs)

So you installed a x64 version of Python ?

Maybe you should try a x32 version Python and install Pygments again.

Zewas (talkcontribs)

In case anyone's interested, here's the solution:

  1. Find the file called pygmentize in the extensions\SyntaxHighlight_GeSHi folder.
  2. Move that file to your Apache's cgi-bin. If your server is set up reasonably well only executables in that magic directory will get executed.
  3. Install Python 2.7 because pygmentize is not really an executable. It's Python byte code and requires the python.exe to run.
  4. Make sure that the Python install directory is added to your system's PATH.
  5. Rename pygmentize to pygmentize.pyc. This is Windows. Extensions are magic here. No extension, no magic.
  6. Find the cgi-bin's AddHandler directive in your httpd.conf and add .pyc to the list if it isn't there already.
  7. Edit your LocalSettings.php and add this line somewhere:
    $wgPygmentizePath = '...\\cgi-bin\\pygmentize.pyc';
  8. Restart your server.

That worked for me.

Paintdog (talkcontribs)

This didn't worked for me (XAMPP-solution), Windows 10, Python 3.7 and Python 2.7. Thank you for sharing your solution, but it didn't worked... (talkcontribs)

Thank you very much! Your info helps me a lot. With the difference: I use IIS as Webserver.

MediaWiki Version 1.29

  1. You need to install Python 2.73 in default directory
  2. Map cgi extensions like here: Extension is "pyc" and not like in the link "py"!)
  3. Find the file called pygmentize in the extensions\SyntaxHighlight_GeSHi folder.Rename pygmentize to pygmentize.pyc. This is Windows. Extensions are magic here. No extension, no magic.
  4. Add this to LocalSettings.php

$wgPygmentizePath = 'C:\inetpub\wwwroot\Wiki\extensions\SyntaxHighlight_GeSHi\pygments\pygmentize.pyc';

wfLoadExtension( 'SyntaxHighlight_GeSHi' );

wfLoadExtension( 'HighlightJS' );

$wgHighlightJsMagic = 'syntaxhighlight';

$wgHighlightJsStyle = 'tomorrow-night-bright'; (talkcontribs)

I've tried this and it's still not working.

Server 2012 R2

IIS 8.5

python 2.73 installed in c:\Python27

Followed instructions above...scratching head. Is there a way to output the error....why it's not highlighting?

Rory.fewell (talkcontribs)

None of this worked for me either, I have gone through the PHP itself and there is little to no information I could find that helped solve the problem.

Instead I have opted to replace the faulty section of code with some basic PHP script that seems to work (at least for my machine).

Try this fix:

Open SyntaxHighlight.class.php in the mediawiki\extensions\SyntaxHighlight_GeSHi folder

Scroll to around line 211 to find the highlight function

Towards the end of this function, you should see an if statement like:

if ( $output === false) {

// does stuff here


Simply replace this entire if block with the following script, and it should fix the problem for you (edit the Python executable path as needed for your installation of course):

if ( $output === false ) {

           $optionPairs = [];

           foreach ( $options as $k => $v ) {

               $optionPairs[] = "{$k}={$v}";


           $execCmd = 'C:\\Python27\\python.exe ' . self::getPygmentizePath() . ' -f html -l ' . $lexer . ' -O ' . implode( ',', $optionPairs );           

           $descriptorSpec = array(

               0 => array('pipe', 'r'),

               1 => array('pipe', 'w')


           $proc = proc_open($execCmd, $descriptorSpec, $pipes);           

           fwrite($pipes[0], $code);


           $output = stream_get_contents($pipes[1]);



           $cache->set( $cacheKey, $output );



This should hopefully be a fix, if the results don't appear straight away it might be due to caching, in which case you can add $output = false; just before the if statement to reset it.

Hope it works for anyone else that's having problems, tested this on IIS 10

Egon.allison (talkcontribs)

I battled with this myself. No matter what i tried it didnt work. Until i discovered this : Extension:Highlightjs Integration. This worked so well for me and i didnt need // wfloadextension( 'syntaxhighlight_geshi' ); in my LocalSettings.php. All i needed to add after following standard instructions (download, paste in folder etc...) was this line : wfloadextension( 'Highlightjs_Integration' ); in my LocalSettings.php

RockSheep (talkcontribs)

Is there a way to make it work in VisualEditor? For me the lines with code are displayed as blank lines.

Egon.allison (talkcontribs)

Hi RockSheep. I dont know the answer to this since I haven't yet played with VisualEditor before. I am sure that there must be a way to get it working since Highlightjs should work in any browser really...

Egon.allison (talkcontribs)

Also as a sidenote if you want to change the style change it in extension.json in the Highlightjs_Integration folder in the "styles" section. Should look like this  :


Egon.allison (talkcontribs) (talkcontribs)

Rory's solution needs a slight tweak in 1.31, but it works mostly, line 307:

I set this in LocalSettings.php and also renamed the pygmentize to pygmentize.pyc and setup a Script Mapping Handler in IIS.

$wgPygmentizePath = 'C:\inetpub\wwwroot\extensions\SyntaxHighlight_GeSHi\pygments\pygmentize.pyc';

$output = $cache->getWithSetCallback(
            $cache->makeGlobalKey( 'highlight', self::makeCacheKeyHash( $code, $lexer, $options ) ),

            function ( $oldValue, &$ttl ) use ( $code, $lexer, $options, &$error ) {

                $optionPairs = [];
                foreach ( $options as $k => $v ) {
                    $optionPairs[] = "{$k}={$v}";

                $execCmd = self::getPygmentizePath() . ' -f html -l ' . $lexer . ' -O ' . implode( ',', $optionPairs );           

                $descriptorSpec = array(
                    0 => array('pipe', 'r'),
                    1 => array('pipe', 'w')

                $proc = proc_open($execCmd, $descriptorSpec, $pipes);           

                fwrite($pipes[0], $code);

                $res = stream_get_contents($pipes[1]);


                return $res;

Harm.frielink (talkcontribs)

SyntaxHighlight uses Python Pygmentize

If you are running MediaWiki on a Shared Host without cpanel installed, forget about using SyntaxHighlight.

It won't work! And that is very very sad!

Why are there python packages needed to make an extension? Don't do that! It is helping the developer to make it easier, but makes the portability of the extension not better, even worse or not working at all. Again very very sad issue here

Reply to "Syntax highlighting does not work"

Requirements for SyntaxHighLight and other extensions

Harm.frielink (talkcontribs)

The extension SyntaxHighLight uses the access to shell of the Webserver it is running on.

Most hosting provider do not give the user access to the shell.

The code of SyntaxHighLight uses the MediaWiki Class Shell which checks if the user has access to the proc_open. See:

* Checks if this class is effectively disabled via php.ini config.
* @return bool disabled
public static function isDisabled() {
  static $disabled = null;

  if ( is_null( $disabled ) ) {
    if ( ! function_exists( 'proc_open' ) ) {
      wfDebug( "proc_open() is disabled\n" );
      $disabled = true;
    } else {
      $disabled = false;
  return $disabled;

There seems not to be another solution available.

My advice to not use the shell for extensions. It won't work.

The other remark is to make a requirements chapter for every extension which gives the user this information BEFORE he is trying to use such an extension!

This requirement chapter can explain which functions and which languages are needed.

There are a number of PHP functions that are disabled in the php.ini by the hosting providers. Examples are disk_total_space, diskfreespace, exec, system, popen, proc_open, proc_nice, shell_exec, passthru, dl

Check your php.ini file or create a website with the function phpinfo();

I would also suggest to use PHP as de-facto without the need to use other languages.

Jdforrester (WMF) (talkcontribs)

My advice to not use the shell for extensions. It won't work.

In the other direction, our advice is not to use hosting providers that don't give you shell access, as it won't work for lots of functionality.

That said, I've added a note reminding sysadmins of this.

Reply to "Requirements for SyntaxHighLight and other extensions"

Call to undefined method MediaWiki\Shell\Command::input()

1 (talkcontribs)
Product Version
MediaWiki 1.31.0-alpha
HHVM 3.21.3 (srv)
MariaDB 10.0.32-MariaDB-0+deb8u1
ICU 52.1
SyntaxHighlight 2.0 (330ac62)12:31, 25 February 2018 GPL-2.0-or-later Provides syntax highlighting <syntaxhighlight> using Pygments - Python syntax highlighter Brion Vibber, Tim Starling, Rob Church, Niklas Laxström, Ori Livneh and Ed Sanders

# /usr/share/nginx/html/wiki/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize -V

Pygments version 2.2.0, (c) 2006-2017 by Georg Brandl. -- PS! I also tried v2.0.2 and specifying the path in LocalSettings.

[error] 683#683: *648 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Call to undefined method MediaWiki\Shell\Command::input() in /usr/share/nginx/html/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php on line 320" while reading response header from upstream, client:, server:, request: "POST /wiki/api.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: ""   

                $output = $cache->getWithSetCallback(

                        $cache->makeGlobalKey( 'highlight', self::makeCacheKeyHash( $code, $lexer, $options ) ),


                        function ( $oldValue, &$ttl ) use ( $code, $lexer, $options, &$error ) {

                                $optionPairs = [];

                                foreach ( $options as $k => $v ) {

                                        $optionPairs[] = "{$k}={$v}";


                                $result = Shell::command(


                                        '-l', $lexer,

                                        '-f', 'html',

                                        '-O', implode( ',', $optionPairs )


                                        ->input( $code )

                                        ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK )


                                if ( $result->getExitCode() != 0 ) {

                                        $ttl = WANObjectCache::TTL_UNCACHEABLE;

                                        $error = $result->getStderr();

                                        return null;


                                return $result->getStdout();



Any tips?

Reply to "Call to undefined method MediaWiki\Shell\Command::input()"
Stra2senBahn (talkcontribs)
Dinoguy1000 (talkcontribs)
Stra2senBahn (talkcontribs)

Thank you,

i know about this ABAP lexer. But I don't know how to use it with SyntaxHighlight. I don't know how to download it (on the listet page there it no download-link), I do't know how to install this lexer and so on.



Dinoguy1000 (talkcontribs)

It should be installed as long as you have this extension installed. To use it you'd use <syntaxhighlight lang="abap">code here</syntaxhighlight>, as can be seen on Wikipedia's ABAP article.

Stra2senBahn (talkcontribs)

Yes, when i use it in this Kind the page get the Category:Pages_with_syntax_highlighting_errors.

And i think ist's a Problem of the Extension, because the ar a Lot of Page with syntax-Highlightling-erros. Look at the link Category:Pages with syntax highlighting errors. eg the lang php or sql doset work also as ABAP.



Dinoguy1000 (talkcontribs)

Try twiddling the capitalization, e.g. Abap or ABAP instead of abap. Apparently the extension is case-sensitive, but there doesn't seem to be a 100% comprehensive list of correct values for the lang attribute.

Stra2senBahn (talkcontribs)

Sorry, but this proposal does not solve the problem.

even using <syntaxhighlight> without the parameter lang generates the error category.



Dinoguy1000 (talkcontribs)

The category is always added if you don't have a lang attribute, since the extension doesn't have a default language, and doesn't have any language auto-detection feature. However, having a lang attribute doesn't guarantee that the categoy won't be added; it is also added if the value of the lang attribute is invalid (though as I said above, there isn't any completely comprehensive list of valid values as far as I'm aware). But, one of the ways the value can be "invalid" is if it isn't the expected capitalization, even though the actual language matching doesn't seem to be case-sensitive in most cases. As long as the actual syntax highlighting works correctly, changing the lang attribute's value to prevent the category from being added isn't terribly important. So, is your code being correctly highlighted when you use <syntaxhighlight lang="abap">?

Stra2senBahn (talkcontribs)

No, the code isn't highlighted! The page, the code looks like using the TAGs <pre>code</pre>

Wen i use <syntaxhighlight lang="abap"> the Page will displayed with the Category:Pages with syntax highlighting errors.


Meinolf Gerling

Dinoguy1000 (talkcontribs)

Is it being highlighted if you use any other capitalization of abap? If not, I'm afraid I'm out of ideas, beyond maybe making sure your MediaWiki installation and the extension are both the latest version, and double-checking the extension's configuration (both if you're able to, of course).

Reply to "Syntax Highlight ABAP-Code"

Failed to invoke Pygments on Windows

Glanthor Reviol (talkcontribs)


I've just migrated and upgraded our company's MediaWiki to a new server. Windows Server 2012 R2, Apache 2.4.33 64bit + PHP 7.1.19 64bit + Python 3.6 64bit, MediaWiki 1.31.0.

Everything works except the SyntaxHighlight extension. The error message:

Notice:  Failed to invoke Pygments: 'C:\Python36\Scripts\pygmentize.exe" "-l" "css" "-f" "html" "-O" "cssclass' is not recognized as an internal or external command, operable program or batch file.

[Called from SyntaxHighlight::highlight in C:\Apache24\htdocs\wiki\extensions\SyntaxHighlight_GeSHi\includes\SyntaxHighlight.php at line 336] in C:\Apache24\htdocs\wiki\includes\debug\MWDebug.php on line 309

The PATH is set correctly, and from a sample test php file I can call Pygments, and it works:


$output = shell_exec('C:\Python36\Scripts\pygmentize.exe -l php -f html -O cssclass C:\Apache24\htdocs\test2.php');

echo "$output2";


I have tried several options, like using the exe: $wgPygmentizePath = "C:\\Python36\\Scripts\\pygmentize.exe"; or the bytecode from the cgi directory:

$wgPygmentizePath = "C:\\Apache24\\cgi-bin\\pygmentize.pyc"; but nothing helped. Please advise how to debug further this problem.

Daimona Eaytoy (talkcontribs)

I'm having the same problem, there are some system config differences (for instance, I run MediaWiki 1.32 master on XAMPP with PHP 7.2.2), but having the same identical error. Having two versions of Python in two different directories, I tried both of them (2.7 and 3.3), changed wgPygmentizePath to all possible combinations, set full user rights on pygmentize, added everything to PATH, but I'm still getting the same error. And, as Glanthor Reviol, I can indeed execute it from wiki folder using windows' cmd and also directly from SyntaxHighlight using exec. I really can't think of something more to do, sounds like there's some specific problem with Windows. BTW, SyntaxHighlight used to work correctly with an old version (can't recall which one) of the extension itself and MediaWiki, using Python 2.7.

Bar-ucholstebro (talkcontribs)

I seem to have the same problem on a MediaWiki 1.31.0, with both Python27 and Python37.

I read somwhere that there were som changes in Shell::command from MediaWiki 1.31.0 - and I traced the problem down to somwhere in that area, but could not find a fix for it.

Hope someone can find a fix for this problem.

Daimona Eaytoy (talkcontribs)

I wrote a short and shallow explanation on phabricator, see Basically, I fear that this might be a very upstream problem, i.e. a PHP bug which won't be fixed (a couple of links on the task) since Windows doesn't actually provide the needed logic. More specifically, the problem as far as I understood it should be that on Windows you cannot set streams as not blocking, which then produces a conflict within shell pipes, entering in a vicious circle. If this is true, there's probably no easy or clean solution to this problem: we could only solve it with a workaround or by refactoring the shell code. But I guess we should really find a solution, since this problem affects a core feature (Shell) on a whole OS.

Fanoudu62219 (talkcontribs)

Hello everyone.

I have the same problem on my side. SyntaxHighlight isn't working since 1.32 update.

I understand the problem with PHP, sream problem etc but I'm looking for a solution, a workaround and since 2 months, I'm unable to find such solution.

Does somebody have a miracle for me ?


Daimona Eaytoy (talkcontribs)

Personally, I can't find one. Actually, I'm not completely sure about the cause, too. Any update will come on Phabricator, anyway.

Fanoudu62219 (talkcontribs)

Thanks for reply.

I am afraid that there is no updates on phabricator too ^^

Wait & see...

Reply to "Failed to invoke Pygments on Windows"

How to add a custom lang named as 'ipl' in SyntaxHighlight_GeSHi

Anu8791 (talkcontribs)


In earlier version "" we are having with /geshi and we able to add custom code for a new lang. But in this latest version 2.0, I don't see how to add the custom code for syntexhighlight.

Could anyone pls help in regards?

PerfektesChaos (talkcontribs)

Please clarify your desire.

  • Do you want to add a synoymous code for an existing scheme?
  • Do you want to establish a new language syntax?

At least for the second you are free to create a new formal language upstream. MediaWiki will import that after half a year, or one year, or later. The same goes for alternative identifiers of existing definitions.

Anu8791 (talkcontribs)

Yes we need to have a new language 'ipl' syntax highlighting in the SyntaxHighlight_GeSHi extension for MediaWiki 1.30.0

Could you let know that how could we archive that ?

PerfektesChaos (talkcontribs)
  • GeSHi has been an external vendor, but for continuous support it has been exchanged by pygments some years ago.
  • Visit upstream:
  • Feed the world with a new language definition.
  • Wait approximately half a year.
  • MediaWiki will swallow the upstream news including yours and update the extension.
  • Then you need to upgrade at least your extension, or perhaps the entire MediaWiki installation (seems to be rather old).
Reply to "How to add a custom lang named as 'ipl' in SyntaxHighlight_GeSHi"
Slowking4 (talkcontribs)
Reply to "pencil icon on editing toolbar"

Pygmentize process getting TimedOut

AhmadF.Cheema (talkcontribs)

Aside from the MediaWiki:Common.css page, any page (MediaWiki:Common.js, Module pages, pages including syntaxhighlight tags) that needs to call Extension:SyntaxHighlight throws out the following process timed out error:

Fatal exception of type "Symfony\Component\Process\Exception\ProcessTimedOutException"

The problematic process according to the logs:

The process "'.../extensions/SyntaxHighlight_GeSHi/pygments/pygmentize' '-l' 'lua' '-f' 'html' '-O' 'cssclass=mw-highlight,encoding=utf-8'" exceeded the timeout of 60 seconds.
  • Tested versions: MediaWiki core (REL1_30) - SyntaxHighlight_GeSHi (REL1_30) - PHP (5.6; 7.0; 7.1; 7.2)

In the case of REL1_31 branch, the process continues to run (and the browser continues to load) indefinitely without throwing out the timed out error. Even when the browser loading has been stopped, the php-cgi command keeps on running in the background and has to be manually terminated through SSH. This could possibly be because composer update removes the "symfony" package.

  • Tested versions: MediaWiki core (REL1_31) - SyntaxHighlight_GeSHi (REL1_31) - PHP (7.0; 7.1; 7.2)
  • Tested versions: MediaWiki core (REL1_31) - SyntaxHighlight_GeSHi (master) - PHP (7.2)

The pygmentize file has execute permissions (755). Also updated composer.

Platform is shared hosting CentOS environment. Process used to work previously, hosting support confirmed not to have made any changes to the server and even tried to run the script after disabling all firewall protections to no avail.

Anyone has any ideas?

Ciencia Al Poder (talkcontribs)

Does it happen on every CSS/JS page, or only some of them? Try to test with a simple CSS/JS page.

I had a similar problem with one specific page, which timed out, probably due to complex code or a bug in the syntax highlight code.

AhmadF.Cheema (talkcontribs)

Aside from MediaWiki:Common.css, on every page.

A confusing update.

  1. $wgMainCacheType (CACHE_MEMCACHED) turned Off - CSS/JS pages work fine.
  2. $wgMainCacheType turned On - CSS/JS pages continue to work fine.
  3. $wgMainCacheType again turned Off - CSS/JS pages start getting timed out.
    1. Comment out any extension - CSS/JS pages start working again.
    2. Re-enable the extension - CSS/JS pages continue to work fine.

Hard-refresh was done after every step. This situation was reproduce-able, however for the moment the issue with CSS/JS pages and any page containing syntaxhighlight tags code blocks appears to have stopped occurring.

However, during none of the steps above, do Module pages work. They continue to get timed out.


Module pages also appear to be working now, waiting for response from hosting provider regarding any changes on their end which might have fixed the issue.

Update II:

Hosting provider confirmed no changes on the server.

Apparently, will never get to the bottom of this.

Will close this issue in the next couple of days, unless any new information comes along.

Ciencia Al Poder (talkcontribs)

Maybe SyntaxHighlight is slow, and it eventually gets the syntax highlight correctly and caches it, so it works correctly next time you visit the page. Of course, this doesn't make sense when you turn off $wgMainCacheType and it still works fine. Maybe the page was cached on your browser and you didn't get to the server when you tried it...

AhmadF.Cheema (talkcontribs)

Possible, though seems doubtful, since I attempted this probably more than 10 times, with hard-refreshes and browser incognito windows.

Tystnaden (talkcontribs)

Do you have Python version 3 installed on the server? The version of Pygments used by the extension bundled with MW 1.31 requires python3 to be installed. I have added a note at the top of this article about this issue.

AhmadF.Cheema (talkcontribs)

I didn't before, but this particular weird issue was probably not linked to python3 as error came and went while using both MediaWiki v1.30 and 1.31 (and their corresponding extension versions). From what I understand python3 is needed when highlighting languages such as Lua, in the absence of python3, MediaWiki just outputs the non-highlighted version with a - Notice: Failed to invoke Pygments: /usr/bin/env: python3: No such file or directory - error in debugging mode.

Tystnaden (talkcontribs)

Okay, that does sound like a different problem.

Daimona Eaytoy (talkcontribs)
Reply to "Pygmentize process getting TimedOut"

How to switch this off?

Summary by Jdforrester (WMF)

Off-topic question about CodeMirror.

Atsirlin (talkcontribs)

SyntaxHighlight was recently rolled out on Russian Wikivoyage, and now I see all my source text in purple, light-green, and other disturbing colors. What is a simple way to switch this off, at least for me personally through my common.css?

Atsirlin (talkcontribs)

My question has been answered. Sorry for trouble.

Mayazcherquoi (talkcontribs)

How can I force Pygmentize to render output using the "colorful" style, as per: ?

I have tried setting the following:

$wgPygmentizePath = '/usr/bin/pygmentize -S colorful';

However, this will just cause Pygmentize to error out on any pages containing a SyntaxHighlight block.


2001:8B0:CA07:C57A:127B:44FF:FE93:FAC4 (talkcontribs)

I too would be interested in how to do this. The <tt>-S</tt> option is not the correct one. I think you would need to edit the source of the extension to add

options['style'] = 'colorful';

However, I think you would also need to edit the <tt>maintenance/updateCSS.php</tt> script to also use that style, and run it, in order to update the CSS files in the <tt>modules/</tt> directory, as these are what define what the output actually looks like.

I tried all of that and although my colour scheme did change, it didn't come out looking correct. I wanted a dark style like a white-on-black terminal, but it persists in giving me a light grey background. Some further clues are missing.

For now I have switched to using the Highlightjs_Integration extension.

Reply to "Control Pygmentize style?"
Return to "SyntaxHighlight" page.