Extension:SyntaxHighlight/ja

これまではSyntaxHighlight_GeSHiとして知られていたSyntaxHighlight拡張機能は、 タグを使用してソースコードの豊富なフォーマットを提供しています. Pygmentsライブラリを使用しており、数百の異なるプログラミング言語とファイル形式をサポートしています.

タグと タグのように、テキストは入力されたとおりに正確にレンダリングされ、空白は保持されます.

使用法
インストールされると、wikiページで 「syntaxhighlight」タグを使用できます. 例えば、

は次のwikitextマークアップの結果です:

古いバージョン（MediaWiki 1.16より前）では、拡張機能は というタグを使用していました. これは引き続きサポートされていますが、ソースコード自体に タグ（XMLなど）が含まれている場合、 は競合を避けるのに役立ちます.

スタイル
表示されたコードが大きすぎる場合は、wikiの MediaWiki:Common.css ページに次のコードを入れて調整することができます（存在しない場合は作成してください）:

コードブロックを境界線で囲むには、上のセクションで のような行を挿入します. 上記のセクションに のような行を挿入することによって、使用される「フォントファミリ」の制御も行えます.

Syntax 強調のエラーのカテゴリ
この拡張機能は、 または タグの 属性が悪いページを追跡カテゴリに追加します. The message key メッセージキーのMediaWiki:syntaxhighlight-error-categoryによりカテゴリ名が決まります. このウィキではCategory:になります.

このカテゴリに誤って分類されるページは、しばしばタグが あるいは にされ 属性がない状態で、エラーの原因はこの拡張機能の旧版の定義が「$wgSyntaxHighlightDefaultLang」をサポートしていたからです. 修正するには属性を または に変更するか、タグに を加えます.

エラーの第2位はサポート外の や の使用です. これらは一般に あるいは で置換してください.

言語
属性により、対応するレクサー（語彙分析）が決まります. 拡張機能がソースコードを強調表示する方式は言語に影響を受けます. pygmentsパーサは大文字小文字を認識し、どの言語も最低1文字は大文字を含みます（小文字のみの言語名はgtags用に割り当てられます. ） サポートする言語の詳細は「言語のサポート」の節を参照してください.

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,  ). Note that the line number specification ignores any renumbering of the displayed line numbers with the  attribute.

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 backwards-compatibility, an  attribute results in the same behavior.

Note that line breaks can occur at any space between the opening and closing tags unless the source code is marked non-breakable with  (on those wikis that support it; see below) or.

For example:

is a lambda expression in Python.

Is the result of:

is a lambda expression in Python.

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:

言語のサポート
Pygmentsライブラリがサポートする言語やコンピュータ言語、ファイル形式は数百あります. 言語の大まかな一覧は次のとおりです.

AppleScript, Assembly, Asymptote, Awk, Befunge, Boo, BrainFuck, C, C++, C#, Clojure, CoffeeScript, ColdFusion, Common Lisp, Coq, Cryptol, Crystal, Cython, D, Dart, Delphi, Dylan, Elm, Erlang, Ezhil, Factor, Fancy, Fortran, F#, Gambas, GAP, Gherkin, GL shaders, Groovy, Haskell, IDL, Io, Java, JavaScript, Lasso, LLVM, Logtalk, Lua, Matlab, MiniD, Modelica, Modula-2, MuPad, Nemerle, Nimrod, Objective-C, Objective-J, Octave, OCaml, PHP, Perl, PovRay, PostScript, PowerShell, Prolog, Python 2.x and 3.x (incl. console sessions and tracebacks), R, REBOL, Red, Redcode, Ruby, Rust, S, S-Plus, Scala, Scheme, Scilab, Smalltalk, SNOBOL, Tcl, Vala, Verilog, VHDL, Visual Basic.NET, Visual FoxPro, XQuery, Zephir

(full list and complete details in the Pygments document) and there are some mappings for some language names which were supported by GeSHi (full list).

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

 * 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:.
 * : Configure the default lexer for some wiki pages. By default this will highlight javascript and css pages. Additional content models can be configured by extensions (e.g. Lua, JSON, ..).


 * 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 the phabricator task on this for further suggestions and information.

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

高度な設定
Unlike the  and   tags, HTML character entities such as   need 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), 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.

関連項目

 * Pygments – Python syntax highlighter
 * 関連する拡張機能:
 * – syntax highlighter that uses Google Code Prettify library.
 * – syntax highlighter that uses SyntaxHighlighter library.
 * – an extension, dependent on this one, to support highlighting text from files viewed via a special page.