Go to file
Ori Livneh 6484894497 Highlight using Pygments rather than Geshi
GeSHi is unmaintained, lacks support for many popular modern languages, and
suffers from deep architectural flaws, chief among them the inconsistent
tokenization of different languages, each of which requires a custom
stylesheet.

Pygments is a well-maintained alternative. It is, by my count, the most popular
syntax highlighting library around. It is BSD-licensed, actively maintained,
and is widely used in PHP projects.

To keep this easy to review, this change does not include update for l10n
files, and it does not delete the geshi/ directory. I will do those in a
separate patch.

The chief change between this and the previous implementation is that errors
result in the code block not being highlighted, as opposed to not being printed
at all, having been replaced by an angry red error message. I think that is the
right user experience. If you go to StackOverflow or GitHub and try to mark up
your code block as being written in some language that their highlighter
doesn't know about, you don't get an error message -- the code simply doesn't
get highlighted.

Because we don't recursively load dependencies for extensions, to test this,
you will need to create a composer.local.json in $IP and add:

    {
        "extra": {
            "merge-plugin": {
                "include": [
                    "extensions/SyntaxHighlight_GeSHi/composer.json"
                ]
            }
        }
    }

Then run `composer update`.

Bug: T85794
Change-Id: I07446ec9893fae3d1e394f435d3d95cf8be6bc33
2015-06-22 23:37:15 +01:00
geshi Re-apply fix for Haskell syntax 2015-04-17 10:46:29 -07:00
i18n Localisation updates from https://translatewiki.net. 2015-06-21 20:05:35 +02:00
maintenance Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
modules Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
.gitignore Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
.gitreview Adding .gitreview 2012-03-23 10:35:01 -07:00
.jscsrc build: Use npm for repo testing (jshint, jsonlint, jscs, banana) 2015-05-29 17:21:59 +00:00
.jshintrc build: Use npm for repo testing (jshint, jsonlint, jscs, banana) 2015-05-29 17:21:59 +00:00
composer.json Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
COPYING Add COPYING 2014-01-22 19:44:32 +00:00
extension.json Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
Gruntfile.js build: Use npm for repo testing (jshint, jsonlint, jscs, banana) 2015-05-29 17:21:59 +00:00
package.json build: Updating development dependencies 2015-06-05 17:14:21 -07:00
README Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
SyntaxHighlight_GeSHi.class.php Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
SyntaxHighlight_GeSHi.compat.php Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
SyntaxHighlight_GeSHi.lexers.php Highlight using Pygments rather than Geshi 2015-06-22 23:37:15 +01:00
SyntaxHighlight_GeSHi.php Revert "Revert "Add extension.json, empty PHP entry point"" 2015-05-20 14:36:46 -07:00

This extension allows source code to be syntax highlighted on the wiki pages.
This README file might be out of date, have a look at the extension page
for updated informations:

    https://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi

== Requirements ==

This version of the extension has been tested with Pygments 1.6, 2.0.2 and
MediaWiki 1.25 as of 2015-06-19. To get releases of this extension compatible
with earlier versions of MediaWiki, visit:

    https://www.mediawiki.org/wiki/Special:ExtensionDistributor/SyntaxHighlight_GeSHi


== Installation ==

First, you will need to ensure that this extension's Composer-managed
dependencies are available. In your root MediaWiki directory, create a
composer.local.json file with the following contents:

    {
        "extra": {
            "merge-plugin": {
                "include": [
                    "extensions/SyntaxHighlight_GeSHi/composer.json"
                ]
            }
        }
    }

Then run 'composer update'.

Next, Add this line to your LocalSettings.php:

    wfLoadExtension( 'SyntaxHighlight_GeSHi' );

You will also need to install Pygments, the syntax highlighting library that
this extension uses. On Ubuntu, Debian, RHEL, CentOS, and Fedora, you can use
your package manager to install the 'python-pygments' package. On other
systems, you can (usually) 'pip install pygments'. For additional help in
obtaining and installing Pygments, please see:

    http://pygments.org/download/

== Usage ==

On the wiki page, you can now use "source" elements:

<source lang="php">
<?php
    v = "string";    // sample initialization
?>
html text
<?php
    echo v;         // end of php code
?>
</source>

== Parameters ==

For details information of these parameters, see the documentation of Pygments'
HtmlFormatter at <http://pygments.org/docs/formatters/#HtmlFormatter>.

* lang;		Defines the language.
* line;		Corresponds to linenos="inline" option.
* start;	Corresponds to linenostart opion.
* highlight;    Corresponds to hl_lines option (comma separated).

== Note ==

Pygments is generous about creating HTML elements: highlighting large blocks of
code can easily generate enough of them to crash a browser. As a guard, syntax
highlighting is turned off for code fragments larger than 100 kB.