Jump to content

Topic on Extension talk:SyntaxHighlight

Syntax highlighting does not work

16
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...

94.217.149.6 (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: http://haishibai.blogspot.de/2011/02/setting-up-python-on-iis-7_01.html(The 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';

209.37.106.160 (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);

           fclose($pipes[0]);           

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

           fclose($pipes[1]);

           proc_close($proc);

           $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  :

"highlight/styles/vs.css"

Egon.allison (talkcontribs)
96.27.170.58 (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 ) ),

            $cache::TTL_MONTH,
            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);
                fclose($pipes[0]);

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

                fclose($pipes[1]);
                proc_close($proc);

                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

Scott216 (talkcontribs)

I'm on a shared host with SiteGround and use cpanel. SyntaxHighlight isn't working for me any more. I guess I'll try another code highlighting extension.

WikimeSteve (talkcontribs)

Is there any news on this failure? We have a rather busy but recently built server. Along with the lack of colorization we also have each of the 98 pages where the tag is called showing up on Category:Pages with syntax highlighting errors. MediaWiki 1.31.0 PHP 7.2.9 (cgi-fcgi) MySQL 5.7.23-log

Will we be better off looking into a different solution like https://www.mediawiki.org/wiki/Extension:SyntaxHighlighterAndCodeColorizer which also shows as stable but a bit older?

Reply to "Syntax highlighting does not work"