Wiki Syntax Highlighting

From Littledamien Wiki
Revision as of 14:33, 30 April 2022 by Video8 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

SyntaxHighlight extension

The SyntaxHighlight extension relies on the Pygments library. [1]

Installation

Add the following line to LocalSettings.php:

wfLoadExtension( 'SyntaxHighlight_GeSHi' );

It's necessary to install the Pygments library on the server.

$ pip3 install Pygments

If the extension is installed somewhere that's not in the PATH, add this line to LocalSettings.php:

$wgPygmentizePath = "/usr/local/bin/pygmentize";

Formatting errors

Pages with incorrectly formatted <syntaxhightligh> tags will be added to a category named pages with syntax highlighting errors.

Any <syntaxhightligh> tag without a lang attribute will log an error. Another common lang attribute error is to set lang="bash" when the only acceptable shell language value is lang="sh". [2]

GeSHI

The following information is deprecated. Keeping it solely for archival purposes.

Use the SyntaxHighlight GeSHi extension.

Download and copy SyntaxHighlight GeSHi extension into the MediaWiki extensions folder.

Customization of the MediaWiki LocalSettings.php file:

$wgAllowUserJs  = true;
$wgAllowUserCss  = true;
require_once("$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php");

Basic usage:

<syntaxhighlight lang="specifyLanguageHere">
your code.
(closing syntaxhighlight tag)

CSS

From within the wiki search for "MediaWiki:Custom.css" or "MediaWiki:Geshi.css" or "MediaWiki:Monobook.css". This will load up the CSS page, which can then be edited to tweak the formatting of the code. More info at [Syntax Highlighting Discussion]

Notes

  1. SyntaxHighlight extension - MediaWiki documentation
  2. Available Lexers - Pygments documentation