Wiki Syntax Highlighting: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== SyntaxHighlight extension ==
The '''SyntaxHighlight''' extension relies on the [http://pygments.org/ Pygments] library. <ref>[https://www.mediawiki.org/wiki/Extension:SyntaxHighlight SyntaxHighlight extension] - MediaWiki documentation</ref>
=== Installation ===
Add the following line to `LocalSettings.php`:
<syntaxhighlight lang="php">
wfLoadExtension( 'SyntaxHighlight_GeSHi' );
</syntaxhighlight>
It's necessary to install the Pygments library on the server.
<syntaxhighlight lang="sh">
$ pip3 install Pygments
</syntaxhighlight>
If the extension is installed somewhere that's not in the PATH, add this line to `LocalSettings.php`:
<syntaxhighlight lang="php">
$wgPygmentizePath = "/usr/local/bin/pygmentize";
</syntaxhighlight>
=== Formatting errors ===
Pages with incorrectly formatted `<syntaxhightligh>` tags will be added to a category named [[:Category:Pages_with_syntax_highlighting_errors|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"`. <ref>[http://pygments.org/docs/lexers/ Available Lexers] - Pygments documentation</ref>
== GeSHI ==
<p class="alert alert-warning">The following information is deprecated. Keeping it solely for archival purposes.</p>
Use the [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi SyntaxHighlight GeSHi extension].
Use the [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi SyntaxHighlight GeSHi extension].


Line 20: Line 54:


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 [[http://www.mediawiki.org/wiki/Extension_talk:Syntax_Highlighting Syntax Highlighting Discussion]]
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 [[http://www.mediawiki.org/wiki/Extension_talk:Syntax_Highlighting Syntax Highlighting Discussion]]
== Notes ==
<references />


[[Category:Wiki_Customization]]
[[Category:Wiki_Customization]]

Revision as of 12:42, 23 July 2018

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