Extension:SyntaxHighlight/pt-br

A extensão SyntaxHighlight, anteriormente conhecida como SyntaxHighlight_GeSHi, fornece formatação rica de código-fonte usando a marcação. Ela é "alimentada" pela biblioteca Pygments e suporta centenas de diferentes linguagens de programação e formatos de arquivos.

Assim como as marcaçõess e , o texto é renderizado exatamente como foi digitado, preservando qualquer espaço em branco.

The SyntaxHighlight extension does not work on hardened wiki installations due to lack of,   and friends. Veja.

A marcação se tornou cara desde a versão 1.39. (Veja .)

Uso
Uma vez instalada, você pode usar marcações "syntaxhighlight" nas páginas wiki. Por exemplo,

é o resultado da seguinte marcação de wikitexto:

Em versões mais antigas (antes do MediaWiki 1.16), a extensão usava a marcação. Isso ainda é suportado, mas está obsoleto. deve ser usada em seu lugar.

Estilo
Se o código exibido for muito grande, você pode ajustá-lo colocando o seguinte na página MediaWiki:Common.css em sua wiki (crie-a se não existir):

Encapsular blocos de código em bordas pode ser feito inserindo uma linha como na seção acima. O controle sobre a família de fontes (font family) usada também pode ser exercido inserindo uma linha como na seção acima.



Categoria de erro de realce de sintaxe
A extensão adiciona páginas que possuem um atributo  inválido em uma marcação  a uma categoria de rastreamento. A chave de mensagem MediaWiki:syntaxhighlight-error-category determina o nome da categoria; nesta wiki é Category:.

O erro mais comum que faz com que as páginas sejam marcadas com esta categoria é uma marcação sem nenhum atributo , porque as versões mais antigas desta extensão suportavam a definição de. Normalmente, elas podem ser substituídas por, ou  ou   podem ser adicionados à marcação.

A categoria também pode ser adicionada, e o conteúdo não será destacado, se houver mais de 1000 linhas ou mais de 100 kB de texto.

lang
O atributo  define qual análise léxica deve ser usada. A linguagem afeta como a extensão realça o código-fonte. See the section #Supported languages for details of supported languages.

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  attribute enables line numbers.

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

highlight
The  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, ) or ranges using two line numbers and a hyphen (for example,  ).

is the result of

inline
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.

For example:

The following  is a lambda expression in Python.

Is the result of:

class
When  is used,   (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 :

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

With :

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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

For example:

Is the result of:



Idiomas suportados
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  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 for details.

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

Programming languages
1=

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
1=

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
1=

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

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.

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


 * Linux:


 * (optional): Absolute path to pygmentize of the Pygments package. The extension bundles the Pygments package and points to the bundled version by default, but you can point to a different version, if you want to. For example:.


 * Windows:


 * If you are hosting your MediaWiki on a Windows machine, you have to set the path for the Pygmentize.exe
 * If there is no  run   from command line inside the   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 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,.


 * Try pointing 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 . After this, the Pygments module can be added to the Python app, for which navigate to the virtual environment path, download and 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:


 * See T128993 on this for further suggestions and information.
 * SELinux can also prevent the extension from running with an error similar to  in your audit.log. This can be allowed with
 * 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  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 for details

Advanced
Unlike the and  tags, HTML character entities such as   need not (and should not) have the   character escaped as. Like the tag but unlike the  tag, tags within the range (other than its own closing tag) need not have the   symbol escaped as , nor does wikitext need to be escaped with a  tag.

Furthermore, while assumes tab stops every 8 characters and renders tabs using actual spaces when the rendered text is copied,  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  tag (not, and not using its own   attribute). The  prefix is required for Firefox (from version 4.0 to version 90), and the   prefix is required for Opera (from version 10.60 to version 15). ( 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.