Wiki Syntax Highlighting: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "Use the [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi|SyntaxHighlight GeSHi extension]. Download and copy SyntaxHighlight GeSHi extension into the MediaWiki ...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Use the [http://www.mediawiki.org/wiki/Extension:SyntaxHighlight_GeSHi|SyntaxHighlight GeSHi extension].
== 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].


Download and copy SyntaxHighlight GeSHi extension into the MediaWiki extensions folder.  
Download and copy SyntaxHighlight GeSHi extension into the MediaWiki extensions folder.  
Line 19: Line 53:
CSS
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 [[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:MediaWiki]]

Latest revision as of 14:33, 30 April 2022

SyntaxHighlight extension[edit]

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

Installation[edit]

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[edit]

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[edit]

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[edit]

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