Extension talk:SyntaxHighlight

Jump to: navigation, search

About this board


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

Tgds003 (talkcontribs)

i have a suggestion.

i want to reduce height of syntaxhighlight element when user doubleclick, so i added some code to Mediawiki:common.js.


$('.mw-highlight pre').dblclick(function(event) {

    if ($(event.target).parent().attr('class') == "scrolldiv") {


    } else {

        $(event.target).wrap('<div class="scrolldiv"/>');

        $('.scrolldiv').css({ height: '300px', overflow: 'auto' });




i thought it would be useful for someone.:)

thank you!

Dinoguy1000 (talkcontribs)

Instead of height, I'd suggest using max-height on .scrolldiv, so that the box won't be unnecessarily tall if there's only a handful of lines of code.

Tgds003 (talkcontribs)

yes, you are right.

but, max-height doesn't seem to work.

i think we should use the 'if' statement rather than max-height.

i edited a code, as follows


$('.mw-highlight pre').dblclick(function(event) {

if (parseInt($(this).css('height'), 10)>300){

if ($(this).parent().attr('class') == "scrolldiv") {


} else {

    $(this).wrap('<div class="scrolldiv"/>');

    $('.scrolldiv').css({ height: '300px', overflow: 'auto' });




Reply to "collapsible syntaxhighlight"
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. (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'; (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?

Reply to "Syntax highlighting does not work"
Aka sektor (talkcontribs)

Not work <syntaxhighlight lang="lua">

Aka sektor (talkcontribs)

Any news? (talkcontribs)

keep format as <nowiki><pre>..</pre></nowiki> but not colourize

on 1.29.1 either

Reply to "MW 1.29.0 bugs"
Brian denton (talkcontribs)

Syntaxhighlight works great for me, except I would like to use wiki markup/wikicode as the language. Is this implemented? I cannot find the lang argument (lang="wikicode" etc) anywhere.

IKhitron (talkcontribs)

It does not exists, unfortunately. You can try html, it can be helpful a little.

Brian denton (talkcontribs)

okay, thank you. PHP has a nice green tinge that looks kinda nice!

Martin Kraft (talkcontribs)

Since there is an wikitext-syntax-highlighting deployed in the new source-code-editor: Wouldn't it be possible to implement the very same functionality into this extension?

Considering, that Wikitext is them most commonly used language inside Wikis, it is really a pity, that we do not have any specific highlighting for help and example pPages.

Reply to "Wikicode as Lang"

Need a way to set a default language for default formatting

Noloader (talkcontribs)

We just installed/configured `SyntaxHighlight_GeSHi` after years of providing sample code without highlighting. We are a C++ library so nearly all of our sample code is C++.

We would like to set the default language to C++ and have GeSHi highlight all `<pre>` code to C++. Over time we will fix the highlighting issues.

Please provide a way to set a default language and have GeSHi highlight for it.

Reply to "Need a way to set a default language for default formatting"

Highlighting the syntax of the result of a template

Loizbec (talkcontribs)


I have a cargo db in my wiki, and I would like to display its content with a JSON syntax. So I created a template that does that. Now I would like to syntax highlight its content. I can't seem to do that, neither by adding the opening tag in the output of the template, nor, of course, by putting the call to the template between syntaxhighlight tags. (I even tried replacing the beginning and the end of my result with the tags after processing the whole content)

Anyone with a solution to that problem ?

Thanks in advance

--Loizbec (talk) 11:09, 16 November 2017 (UTC)

PerfektesChaos (talkcontribs)

If I understand correctly what you want to do, try this:


First, template cargo will be expanded, then result hilited.

Loizbec (talkcontribs)

Great !!! It works. Thanks a lot !

Reply to "Highlighting the syntax of the result of a template"
Seppl2013 (talkcontribs)

With the old "extension" for syntax highlighting GeSHi http://qbnz.com/highlighter/ i had created my own language highlighting files for some languages. I would now like to migrate those to pygmentize and add even more languages.


explains the principle and http://pygments.org/docs/lexerdevelopment/#adding-and-testing-a-new-lexer how to add and test lexers.

How do I add such a lexer to be "picked up" in the mediawiki environment?

What would be an "update safe" way to do this and if there is none yet where can I post a feature request for this?

Seppl2013 (talk) 08:57, 26 September 2017 (UTC)

PerfektesChaos (talkcontribs)

I am afraid you are to wait a while.

As far as I understand the procedure the entire pygments definitions are updating MediaWiki on a regular base.

That might happen once a year, after a couple of months, some years later. If an important language has been added to pygments, or a serious bug in a frequently used language pattern has been fixed, someone might feel urged to import the current state.

It looks rather settled to me now, and you might show a great advantage in a major language not yet supported to trigger an update.

Reply to "Adding new Languages"
Garonenur (talkcontribs)
1 INSTERT INTO test (value) VALUES (0);

It works in this wiki, but on our company-wiki (which is not open, so no links) zeros get swallowed. and

<syntaxhighlight lang="mysql" enclose="div" line>
INSTERT INTO test (value) VALUES (0);

leads to the zero not being shown. I tested pygmentize on the command line and it outputs the sql correctly.

Any ideas? Questions?

MichaelFrey (talkcontribs)

Could you please state the version of Mediawiki and Extension being used?

Could you post a screenshoot and the HTML code delivered to the browser for this example?

When I render it here on mediawiki.org, the zero is encoded with:

<span class="mi">0</span>

So, I would presume, that your company wiki has done something with the CSS-class "mi".

Garonenur (talkcontribs)

hi Michael,

MediaWiki: 1.27.1

SyntaxHighlight: 2.0



The class is set correct, but the '0's are missing in the HTML. If I change the source to something nonsens like a letter or even '00' those show up (on page and in raw html)

If anything happens to css-classes here in my wiki, it is because of me, as I have to handle the wiki.

[edit: fixed file link typo]

IKhitron (talkcontribs)

You can open the console and check the code of the element of first png.

Garonenur (talkcontribs)

which console? for which code? I have terminal acces to the ubuntu server running the wiki - or are you refering to the web-console like fire-bug?

IKhitron (talkcontribs)

You mean the first png is not from the browser? It looks very nice.

Garonenur (talkcontribs)

both images are screenshots from browser and firebug.

I just realized that I had a typo in the second file-link:


thats the html I get for the syntax highlighted sql-code.

Garonenur (talkcontribs)

I just realized that a zero in simple <code>0</code> tags is not rendered by my wiki also, so this may have nothing to do with SyntaxHighlight.

This post was hidden by IKhitron (history)
Reply to "Zeros in SQL go missing"
Elitre (WMF) (talkcontribs)

My apostrophes come in light blue, which makes them even less noticeable than usual, which kinda defeats the point, I think? :)

Elitre (WMF) (talkcontribs)

Aaand the page I was actually looking for for this feedback was Extension talk:CodeMirror...

SELinux causing "Pages with syntax highlighting errors"

Christopher.ursich (talkcontribs)

The problem of SELinux causing SyntaxHighlight (specifically, Pygments) to not work, and to tag the page into category "Pages with syntax highlighting errors" has been discussed on this forum previously, and in other places. MediaWiki addresses it in article SELinux, but I believe the instructions there are somewhat incorrect. I solved the problem for myself, and proposed changes to the article on Talk:SELinux. I hope this helps.

Reply to "SELinux causing "Pages with syntax highlighting errors""