This extension comes with MediaWiki 1.21 and above. Thus you do not have to download it again. However, you still need to follow the other instructions provided.
For syntax highlighting of wikitext when using the source editor, see the CodeMirror extension or the userscripts of Remember the dot and Cacycle.

MediaWiki extensions manual
SyntaxHighlight
Release status: stable
Implementation Tag
Description Allows source code to be syntax highlighted on the wiki pages
Author(s)
  • Brion Vibber,
  • Tim Starling,
  • Rob Church,
  • Ori Livneh
Latest version continuous updates
Compatibility policy Master maintains backward compatibility.
MediaWiki 1.25+
Database changes No
Composer mediawiki/syntax-highlight
License GNU General Public License 2.0 or later
Download
README
Parameters
  • $wgPygmentizePath
  • $wgSyntaxHighlightMaxLines
  • $wgSyntaxHighlightMaxBytes
Tags
<syntaxhighlight>
Hooks used
  • ApiFormatHighlight
  • ContentGetParserOutput
  • ParserFirstCallInit
  • SoftwareInfo
Public wikis using 11,760 (Ranked 8th)
Translate the SyntaxHighlight extension
Issues Open tasks · Report a bug

The SyntaxHighlight extension, formerly known as SyntaxHighlight_GeSHi, provides rich formatting of source code using the <syntaxhighlight> tag. It is powered by the Pygments library and supports hundreds of different programming languages and file formats.

Like the <pre> and <poem> tags, the text is rendered exactly as it was typed, preserving any white space.

The SyntaxHighlight extension does not work on hardened wiki installations due to lack of proc_open, shell_exec and friends. See task T250763.

The <syntaxhighlight> tag has become expensive since 1.39. (See task T316858.)

Usage

Once installed, you can use "syntaxhighlight" tags on wiki pages. For example,

def quick_sort(arr):
	less = []
	pivot_list = []
	more = []
	if len(arr) <= 1:
		return arr
	else:
		pass

is the result of the following wikitext markup:

<syntaxhighlight lang="python" line>
def quick_sort(arr):
	less = []
	pivot_list = []
	more = []
	if len(arr) <= 1:
		return arr
	else:
		pass
</syntaxhighlight>

In older versions (before MediaWiki 1.16), the extension used the tag <source>. This is still supported, but is deprecated. <syntaxhighlight> should be used instead.

Styling

If the displayed code is too big, you can adjust it by putting the following into the MediaWiki:Common.css page in your wiki (create it if it does not exist):

/* <translate nowrap><!--T:106--> CSS placed here will be applied to all skins</translate> */
.mw-highlight pre {
	font-size: 90%;
}

Encasing code blocks in borders can be done by inserting a line like border: 1px dashed blue; in the section above. Control over font family used can also be exercised by inserting a line like font-family: "Courier New", monospace; into the section above.

Syntax highlighting error category

The extension adds pages that have a bad lang attribute in a <syntaxhighlight> tag to a tracking category. The message key MediaWiki:syntaxhighlight-error-category determines the category name; on this wiki it is Category:Pages with syntax highlighting errors.

The most common error that leads to pages being tagged with this category is a <syntaxhighlight> tag with no lang attribute at all, because older versions of this extension supported the definition of $wgSyntaxHighlightDefaultLang. These can typically either be replaced with <pre>, or lang="bash" or lang="text" can be added to the tag.

The category may also be added, and the content will not be highlighted, if there are more than 1000 lines or more than 100 kB text.[1]

Parameters

lang

The lang="name" attribute defines what lexer should be used. The language affects how the extension highlights the source code. See the section #Supported languages for details of supported languages.

def quick_sort(arr):
    less = []
<syntaxhighlight lang="python">
...
</syntaxhighlight>

Specifying an invalid or unknown name will tag the page with a tracking category. See the section #Syntax highlighting error category in this page for details.

line

The line attribute enables line numbers.

def quick_sort(arr):
	less = []
<syntaxhighlight lang="python" line>
...
</syntaxhighlight>

start

The start attribute (in combination with line) defines the first line number of the code block. For example, line start="55" will make line numbering start at 55.

def quick_sort(arr):
    less = []
<syntaxhighlight lang="python" line start="55">
...
</syntaxhighlight>

highlight

The highlight attribute specifies one or more lines that should be marked (by highlighting those lines with a different background color). You can specify multiple line numbers separated by commas (for example, highlight="1,4,8") or ranges using two line numbers and a hyphen (for example, highlight="5-7").

The line number specification ignores any renumbering of the displayed line numbers with the start attribute.
def quick_sort(arr):
    less = []
    pivot_list = []
    more = []
    if len(arr) <= 1:
        return arr

is the result of

<syntaxhighlight lang="python" line start="3" highlight="1,5-7">
...
</syntaxhighlight>

inline

MediaWiki version:
1.26

The attribute indicates that the source code should be inline as part of a paragraph (as opposed to being its own block). This option is available starting with MediaWiki 1.26.

Using the "enclose" parameter is deprecated; if set to "none", it should be replaced with inline; otherwise, it can be removed entirely.
Line breaks can occur at any space between the opening and closing tags unless the source code is marked non-breakable with class="nowrap" (on those wikis that support it; see below) or style="white-space:nowrap".

For example:

The following lambda x: x * 2 is a lambda expression in Python.

Is the result of:

The following <syntaxhighlight lang="python" inline>lambda x: x * 2</syntaxhighlight> is a [[w:Lambda (programming)|lambda expression]] in Python.

class

When inline is used, class="nowrap" (on those wikis that support it; not on MediaWiki itself) specifies that line breaks should not occur at spaces within the code block.

For example:

Without class="nowrap":

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlambda x: x * 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

With style="white-space:nowrap":

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxlambda x: x * 2xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

style

The style attribute allows CSS attributes to be included directly. This is equivalent to enclosing the block in a <div> (not <span>) tag. The tab‑size attribute cannot be specified this way; it requires an enclosing <span> tag as described below under Advanced.

For example:

def quick_sort(arr):
	less = []
	pivot_list = []
	more = []
	if len(arr) <= 1:
		return arr
	else:
		pass

Is the result of:

<syntaxhighlight lang="python" style="border: 3px dashed blue;">
def quick_sort(arr):
	less = []
	pivot_list = []
	more = []
	if len(arr) <= 1:
		return arr
	else:
		pass
</syntaxhighlight>

Supported languages

Pygments provides support for syntax-highlighting hundreds of computer languages and file formats through the various "lexers" included with the library.

In most cases, the lang= attribute to be used with this extension is the lower-case version of the name of the language. However, many have aliases, or "short names" as they're called in the Pygments documentation; see "Available lexers" for full details.

Some languages previously supported by GeSHi have been mapped to Pygments lexers; see SyntaxHighlightGeSHiCompat.php for details.

Pygments provides a "wikitext" lexer since April 2023. In older versions, use "html+handlebars" or "moin" instead.

As of January 2020, the full list of languages supported by Pygments is:

    Programming languages

    • ActionScript
    • Ada
    • Agda (incl. literate)
    • Alloy
    • AMPL
    • ANTLR
    • APL
    • AppleScript
    • Assembly (various)
    • Asymptote
    • Augeas
    • AutoIt
    • Awk
    • BBC Basic
    • Befunge
    • BlitzBasic
    • Boa
    • Boo
    • Boogie
    • BrainFuck
    • C, C++ (incl. dialects like Arduino)
    • C#
    • Chapel
    • Charm++ CI
    • Cirru
    • Clay
    • Clean
    • Clojure
    • CoffeeScript
    • ColdFusion
    • Common Lisp
    • Component Pascal
    • Coq
    • Croc (MiniD)
    • Cryptol (incl. Literate Cryptol)
    • Crystal
    • Cypher
    • Cython
    • D
    • Dart
    • DCPU-16
    • Delphi
    • Dylan (incl. console)
    • Eiffel
    • Elm
    • Emacs Lisp
    • Email
    • Erlang (incl. shell sessions)
    • Ezhil
    • Factor
    • Fancy
    • Fantom
    • Fennel
    • FloScript
    • Forth
    • Fortran
    • FreeFEM++
    • F#
    • GAP
    • Gherkin (Cucumber)
    • GLSL shaders
    • Golo
    • Gosu
    • Groovy
    • Haskell (incl. Literate Haskell)
    • HLSL
    • HSpec
    • Hy
    • IDL
    • Idris (incl. Literate Idris)
    • Igor Pro
    • Io
    • Jags
    • Java
    • JavaScript
    • Jasmin
    • Jcl
    • Julia
    • Kotlin
    • Lasso (incl. templating)
    • Limbo
    • LiveScript
    • Logtalk
    • Logos
    • Lua
    • Mathematica
    • Matlab
    • Modelica
    • Modula-2
    • Monkey
    • Monte
    • MoonScript
    • Mosel
    • MuPad
    • NASM
    • Nemerle
    • NesC
    • NewLISP
    • Nimrod
    • Nit
    • Notmuch
    • NuSMV
    • Objective-C
    • Objective-J
    • Octave
    • OCaml
    • Opa
    • OpenCOBOL
    • ParaSail
    • Pawn
    • PHP
    • Perl 5
    • Pike
    • Pony
    • PovRay
    • PostScript
    • PowerShell
    • Praat
    • Prolog
    • Python (incl. console sessions and tracebacks)
    • QBasic
    • Racket
    • Raku a.k.a. Perl 6
    • REBOL
    • Red
    • Redcode
    • Rexx
    • Ride
    • Ruby (incl. irb sessions)
    • Rust
    • S, S-Plus, R
    • Scala
    • Scdoc
    • Scheme
    • Scilab
    • SGF
    • Shell scripts (Bash, Tcsh, Fish)
    • Shen
    • Silver
    • Slash
    • Slurm
    • Smalltalk
    • SNOBOL
    • Snowball
    • Solidity
    • SourcePawn
    • Stan
    • Standard ML
    • Stata
    • Swift
    • Swig
    • SuperCollider
    • Tcl
    • Tera Term language
    • TypeScript
    • TypoScript
    • USD
    • Unicon
    • Urbiscript
    • Vala
    • VBScript
    • Verilog, SystemVerilog
    • VHDL
    • Visual Basic.NET
    • Visual FoxPro
    • Whiley
    • Xtend
    • XQuery
    • Zeek
    • Zephir
    • Zig

    Template languages

    • Angular templates
    • Cheetah templates
    • ColdFusion
    • Django / Jinja templates
    • ERB (Ruby templating)
    • Evoque
    • Genshi (the Trac template language)
    • Handlebars
    • JSP (Java Server Pages)
    • Liquid
    • Myghty (the HTML::Mason based framework)
    • Mako (the Myghty successor)
    • Slim
    • Smarty templates (PHP templating)
    • Tea
    • Twig

    Other markup

    • Apache config files
    • Apache Pig
    • BBCode
    • CapDL
    • Cap'n Proto
    • CMake
    • Csound scores
    • CSS
    • Debian control files
    • Diff files
    • Dockerfiles
    • DTD
    • EBNF
    • E-mail headers
    • Extempore
    • Flatline
    • Gettext catalogs
    • Gnuplot script
    • Groff markup
    • Hexdumps
    • HTML
    • HTTP sessions
    • IDL
    • Inform
    • INI-style config files
    • IRC logs (irssi style)
    • Isabelle
    • JSGF notation
    • JSON, JSON-LD
    • Lean theorem prover
    • Lighttpd config files
    • Linux kernel log (dmesg)
    • LLVM assembly
    • LSL scripts
    • Makefiles
    • MoinMoin/Trac Wiki markup
    • MQL
    • MySQL
    • NCAR command language
    • Nginx config files
    • Nix language
    • NSIS scripts
    • Notmuch
    • POV-Ray scenes
    • Puppet
    • QML
    • Ragel
    • Redcode
    • ReST
    • Roboconf
    • Robot Framework
    • RPM spec files
    • Rql
    • RSL
    • Scdoc
    • SPARQL
    • SQL, also MySQL, SQLite
    • Squid configuration
    • TADS 3
    • Terraform
    • TeX
    • Thrift
    • TOML
    • Treetop grammars
    • USD (Universal Scene Description)
    • Varnish configs
    • VGL
    • Vim Script
    • WDiff
    • Windows batch files
    • XML
    • XSLT
    • YAML
    • Windows Registry files
    Since MediaWiki 1.37 more lexers were added with the update of pygments to version 2.10.0 as detailed with task T280117.
    • ansys
    • apdl
    • asc
    • gcode
    • golang === go
    • gsql
    • jslt
    • julia-repl
    • kuin
    • meson
    • nestedtext
    • nodejsrepl
    • nt
    • omg-idl
    • output
    • pem
    • procfile
    • pwsh
    • smithy
    • teal
    • thingsdb
    • ti
    • wast
    • wat

    Lexers previously supported by GeSHi

    Below is a partial list of languages that GeSHi could highlight, with strike-through for languages no longer supported after the switch to Pygments.

    Lexers previously supported by GeSHi
    Code Language
    4csGADV 4CS
    6502acmeMOS 6502 (6510) ACME Cross Assembler
    6502kickassMOS 6502 (6510) Kick Assembler
    6502tasmMOS 6502 (6510) TASM/64TASS
    68000devpacMotorola 68000 - HiSoft Devpac ST 2 Assembler
    abapABAP
    actionscriptActionScript
    actionscript3ActionScript3
    adaAda
    algol68ALGOL 68
    apacheApache Configuration
    applescriptAppleScript
    apt_sourcesApt sources
    armARM Assembler
    asmAssembly
    aspActive Server Pages (ASP)
    asymptoteAsymptote
    autoconfAutoconf
    autohotkeyAutoHotkey
    autoitAutoIt
    avisynthAviSynth
    awkAWK
    bascomavrBASCOM AVR
    bashBash
    basic4glBasic4GL
    bfBrainfuck
    bibtexBibTeX
    blitzbasicBlitz BASIC
    bnfBackus–Naur Form
    booBoo
    cC
    c_loadrunnerC Loadrunner
    c_macC (Mac)
    caddclAutoCAD DCL
    cadlispAutoLISP
    cfdgCFDG
    cfmColdFusion Markup Language
    chaiscriptChaiScript
    cilCommon Intermediate Language (CIL)
    clojureClojure
    cmakeCMake
    cobolCOBOL
    coffeescriptCoffeeScript
    cppC++
    cpp-qtC++ (Qt toolkit)
    cshC shell
    csharpC#
    cssCascading Style Sheets (CSS)
    cuesheetCue sheet
    dD
    dartDart
    dclData Control Language
    dcpu16DCPU-16
    dcsData Conversion System
    delphiDelphi
    diffDiff
    divDIV
    dosbatchDOS batch file
    dotDOT
    eE
    ebnfExtended Backus–Naur Form
    ecmascriptECMAScript
    eiffelEiffel
    emailEmail (mbox \ eml \ RFC format)
    epcEnerscript
    erlangErlang
    euphoriaEuphoria
    f1Formula One
    falconFalcon
    foFO
    fortranFortran
    freebasicFreeBASIC
    freeswitchFreeSWITCH
    fsharpFsharp
    gambasGambas
    gdbGDB
    generoGenero
    genieGenie
    gettextgettext
    glslOpenGL Shading Language (GLSL)
    gmlGame Maker Language (GML)
    gnuplotgnuplot
    goGo
    groovyGroovy
    gwbasicGW-BASIC
    haskellHaskell
    haxeHaxe
    hicestHicEst
    hq9plusHQ9+
    html4strictHTML
    html5HTML5
    iconIcon
    idlUno IDL
    iniINI
    innoInno
    intercalINTERCAL
    ioIo
    jJ
    javaJava
    java5Java(TM) 2 Platform Standard Edition 5.0
    javascriptJavaScript
    jqueryjQuery
    kixtartKiXtart
    klonecKlone C
    klonecppKlone C++
    kotlinKotlin
    kshKorn shell
    latexLaTeX
    lbLiberty BASIC
    ldifLDAP Data Interchange Format
    lispLisp
    llvmLLVM
    locobasicLocomotive BASIC
    logtalkLogtalk
    lolcodeLOLCODE
    lotusformulasFormula language
    lotusscriptLotusScript
    lscriptLightWave 3D
    lsl2Linden Scripting Language
    luaLua
    magiksfMagik
    m68kMotorola 68000 Assembler
    makemake
    mapbasicMapBasic
    matlabMATLAB M
    mircmIRC scripting language
    mmixMMIX
    modula2Modula-2
    modula3Modula-3
    mpasmMicrochip Assembler
    mxmlMXML
    mysqlMySQL
    nagiosNagios
    netrexxNetRexx
    newlispNewLISP
    nsisNullsoft Scriptable Install System (NSIS)
    oberon2Oberon-2
    objcObjective-C
    objeckObjeck
    ocamlOCaml
    ocaml-briefOCaml
    octaveOctave
    oobasLibreOffice/OpenOffice.org Basic
    oorexxObject REXX
    oracle11Oracle 11 SQL
    oracle8Oracle 8 SQL
    oxygeneOxygene
    ozOz
    parasailParaSail
    parigpPARI/GP
    pascalPascal
    pcrePerl Compatible Regular Expressions
    perper
    perlpl
    Perl
    perl6
    pl6
    raku
    Perl 6
    pfPF
    phpPHP
    php-briefPHP (deprecated no colors, odd framing)
    pic16PIC assembly language
    pikePike
    pixelbenderPixel Bender
    pliPL/I
    plsqlPL/SQL
    postgresqlPostgreSQL
    postscriptPostScript
    povrayPersistence of Vision Raytracer
    powerbuilderPowerBuilder
    powershellWindows PowerShell
    proftpdProFTPD
    progressOpenEdge Advanced Business Language
    prologProlog
    propertiesProperties file
    providexProvideX
    purebasicPureBasic
    pyconPython
    pys60PyS60
    python
    py
    python3
    py3
    Python
    python2
    py2
    Python 2
    qQ
    qbasicQBasic/QuickBASIC
    rails Rails
    rebolRebol
    regWindows Registry
    rexxRexx
    robotsrobots.txt
    rpmspecRPM Spec files
    rsplusR
    ruby Ruby
    sasSAS
    scalaScala
    schemeScheme
    sh
    shell
    shell-session
    Shell Script (POSIX)
    scilabScilab
    sdlbasicSdlBasic
    smalltalkSmalltalk
    smartySmarty
    sparkSPARK
    sparqlSPARQL
    sqlSQL
    stonescriptStoneScript (Scripting language for ShiVa3D)
    systemverilogSystemVerilog
    tcshTcsh
    tclTcl
    teraterm Tera Term
    textPlain text
    thinbasicthinBasic
    tsTypeScript
    tsqlTransact-SQL
    typoscriptTypoScript
    uniconUnicon
    upcUnified Parallel C
    urbiURBI
    uscriptUnrealScript
    valaVala
    vbVisual Basic
    vbnetVisual Basic .NET
    veditVEDIT
    verilogVerilog
    vhdlVHDL
    vimVim script
    visualfoxproVisual FoxPro
    visualprologVisual Prolog
    whitespaceWhitespace
    whoisWhois
    winbatchWinbatch
    xmlXML
    xorg_confXorg.conf
    yamlYAML
    xppMicrosoft Dynamics AX
    z80ZiLOG Z80 Assembler
    zxbasicZXBasic

    Installation

    The version of this extension bundled with MediaWiki 1.31 requires Python version 3 (python3) to be installed on the server. This is a change from the version bundled with MediaWiki 1.30, which used Python version 2 (python). Note that the python3 binary must be installed in the execution PATH of the PHP interpreter.
    Despite its update to Pygments (and away from GeSHi) and despite its updated name, this extension internally still uses the former file names as stated below.
    • Download and place the file(s) in a directory called SyntaxHighlight_GeSHi in your extensions/ folder.
    • Only when installing from Git, run Composer to install PHP dependencies, by issuing composer install --no-dev in the extension directory. (See task T173141 for potential complications.)
    • Add the following code at the bottom of your LocalSettings.php file:
      wfLoadExtension( 'SyntaxHighlight_GeSHi' );
      
    • In Linux, set execute permissions for the pygmentize binary. You can use an FTP client or the following shell command to do so:
    chmod a+x /path/to/extensions/SyntaxHighlight_GeSHi/pygments/pygmentize
    
    • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


    Vagrant installation:

    • If using Vagrant , install with vagrant roles enable syntaxhighlight --provision
    When installing from Git, please note that starting from MediaWiki 1.26, and ending with MediaWiki 1.31 this extension requires Composer.

    So, after installation from Git change to the directory containing the extension e.g. "../extensions/SyntaxHighlight_GeSHi/" and run composer install --no-dev, or when updating: composer update --no-dev.

    Alternatively as well as preferably add the line "extensions/SyntaxHighlight_GeSHi/composer.json" to the "composer.local.json" file in the root directory of your wiki like e.g.
    {
    	"extra": {
    		"merge-plugin": {
    			"include": [
    				"extensions/SyntaxHighlight_GeSHi/composer.json"
    			]
    		}
    	}
    }
    
    Now run composer update --no-dev. Voilà!
    Warning Warning: When uploading the extension via FTP be sure to upload the pygments/pygmentize file with the transfer type binary.

    Configuration

    $wgSyntaxHighlightMaxLines and $wgSyntaxHighlightMaxBytes (optional): For performance reasons, blobs or pages (JS, Lua and CSS pages) larger than these values will not be highlighted. (since 1.40)

    Linux
    • $wgPygmentizePath (optional): Absolute path to pygmentize of the Pygments package. The extension bundles the Pygments package and $wgPygmentizePath points to the bundled version by default, but you can point to a different version, if you want to. For example: $wgPygmentizePath = "/usr/local/bin/pygmentize";.
    Windows
    • If you are hosting your MediaWiki on a Windows machine, you have to set the path for the Pygmentize.exe $wgPygmentizePath = "c:\\Python27\\Scripts\\pygmentize.exe";
      • If there is no pygmentize.exe run easy_install Pygments from command line inside the Scripts folder to generate the file.

    If you are using the bundled pygmentize binary (extensions/SyntaxHighlight_GeSHi/pygments/pygmentize), make sure your webserver is permitted to execute it. If your host does not allow you to add executables to your web directory, install python-pygments and add $wgPygmentizePath = pygmentize to LocalSettings.php.

    Troubleshooting

    After updating to MediaWiki v1.26 and above, some users started reporting problems with the extension. There could be cases, when some languages, such as Lua might not get highlighted and by turning on debugging, MediaWiki would throw out the error, Notice: Failed to invoke Pygments: /usr/bin/env: python3: No such file or directory.

    • Try pointing $wgPygmentizePath in LocalSettings.php towards an external pygmentize binary.
    • In shared hosting environments with cPanel, this can be done by setting up a new Python application through the "Setup Python App" menu, and activating the virtual environment for the app through SSH (source /virtualenv/python/3.5/bin/activate). After this, the Pygments module can be added to the Python app, for which navigate to the virtual environment path (cd virtualenv/python/3.5/bin/), download and install Pygments (./pip install Pygments) and then activate the module by adding "Pygments" under the "Existing applications" section of the "Setup Python App" menu. This will create the required file at path: virtualenv/python/3.5/bin/pygmentize
    • See phab:T128993 on this for further suggestions and information.
    • SELinux can also prevent the extension from running with an error similar to type=AVC msg=audit(1609598265.169:225924): avc: denied { execute } for pid=2360888 comm="bash" name="pygmentize" dev="dm-0" ino=50814399 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_user_content_t:s0 tclass=file permissive=0 in your audit.log. This can be allowed with setsebool -P httpd_unified 1
    • In earlier versions of this extension, Windows would sometimes fail with an _Py_HashRandomization_Init error. This was a bug with the Windows environment not being passed to python executions. A fix was released in 1.40, with backports to 1.38 and 1.39.

    VisualEditor integration

    The plugin enables direct editing with VisualEditor. A popup is opened when a user wants to edit syntaxhighlight sections. For this to work, VisualEditor must be installed and configured from the latest Git version, same for Parsoid. The feature may not work with older Parsoid versions. See Extension:SyntaxHighlight/VisualEditor for details

    Advanced

    Unlike the <pre> and <code> tags, HTML character entities such as &nbsp; need not (and should not) have the & character escaped as &amp;. Like the <pre> tag but unlike the <code> tag, tags within the range (other than its own closing tag) need not have the < symbol escaped as &lt;, nor does wikitext need to be escaped with a <nowiki> tag.

    Furthermore, while <pre> assumes tab stops every 8 characters and renders tabs using actual spaces when the rendered text is copied, <syntaxhighlight> uses 4-space tab stops (except Internet Explorer, which uses 8) and preserves the tab characters in the rendered text; the latter may be changed using an enclosing <span style="-moz-tab-size: nn; -o-tab-size: nn; tab-size: nn;"> tag (not <div>, and not using its own style attribute). The -moz- prefix is required for Firefox (from version 4.0 to version 90), and the -o- prefix is required for Opera (from version 10.60 to version 15).[2] ( Note that the wiki editing box assumes 8-space tabs.) This applies only to actual saved pages; previews generated through an edit box or Special:ExpandTemplates may differ.

    See also

    • Extensions dependent on this one:
      • Extension:SyntaxHighlightPages highlights pages based on title suffixes.
    • Alternative extensions:
      • Extension:Highlightjs Integration syntax highlighter that uses HighlightJS library (includes support for some languages that are missing from Pygments, such as Maxima).
      • Extension:GoogleCodePrettify syntax highlighter that uses Google Code Prettify library.

    Footnotes

    This article is issued from Mediawiki. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.