Extension:SyntaxHighlight/ja

The SyntaxHighlight GeSHi extension allows to display formatted source code with the   tag.

This extension also adds coloring according to the code language settings. Like the  tags and the   tags, the tags shows the coding exactly as it was typed, preserving white space.

This extension also can create line numbers.

使用法
ウィキページ上で, you can now use "syntaxhighlight" elements:

を使用すると、結果は:

となります.

&lt;source&gt; タグの代替
50696の前では, the extension used the tag. これはまだサポートされていますが、 しかし  はコード自身に
 * プログラム言語を指定します 対応プログラム言語は"Supported languages"をご覧ください


 * Type of line numbering to use. If you do not provide this parameter, then lines will not be numbered. Corresponds to the enable_line_numbers flag in GeSHi.
 * Type of line numbering to use. If you do not provide this parameter, then lines will not be numbered. Corresponds to the enable_line_numbers flag in GeSHi.


 * Equivalent to
 * Equivalent to


 * 行表示の開始位置を指定します とすると55から開始され 55、56、57...のように続きます
 * 行表示の開始位置を指定します とすると55から開始され 55、56、57...のように続きます


 * 強調する行数を指定します. line start="??"は関係ありません
 * 強調する行数を指定します. line start="??"は関係ありません


 * Specifies what container is used to enclose the source code. Takes values "pre" (default value), "div", "none". Corresponds to set_header_type method on GeSHi. Choosing "div" will cause text to wrap, which is helpful if text is extending off the edge of the screen, causing horizontal scrolling.
 * Specifies what container is used to enclose the source code. Takes values "pre" (default value), "div", "none". Corresponds to set_header_type method on GeSHi. Choosing "div" will cause text to wrap, which is helpful if text is extending off the edge of the screen, causing horizontal scrolling.


 * Type the name of the parameter to enable the strict mode. Corresponds to enable_strict_mode method on GeSHi.
 * Type the name of the parameter to enable the strict mode. Corresponds to enable_strict_mode method on GeSHi.

The effect and usage of these parameters can be consulted in GeSHi's documentation.

Since r22246, you can override the colors using MediaWiki:Geshi.css.

その他の使用法
When line numbering is added with line, long code lines will be wrapped. See the example below. When text is the selected language, and numbering is used, the behaviour resembles the use of pre tags with numbering and long-line wrapping.

The following example shows how to color an HTML code listing:

A typical result is just:

対応言語
These are the languages known by GeSHi that can be used in the lang parameter.

Note that installed GeSHi version (can be revealed by previewing e.g. ) might not be the most recent version;  see 10967 for Wikimedia sites.

The GeSHi sources for each language can be found in VCS on SourceForge. Remember to go and select the version that the MediaWiki installation uses.

既定のソース言語
Added in 50693.

If the site mainly quotes the source code of a specific programming language, it would be helpful to set a default language.

To do so, add a new variable to LocalSettings.php, just after the require_once line. We set C programming language as an example:

インストール
The MediaWiki extension requires the GeSHi project files from SourceForge to work! To make this easier to install and maintain, the extension in git includes the Geshi project in a subdirectory named.

注記:
 * GeSHi 1.1.2alpha3 does not work with the MediaWiki extension.
 * You can delete the extensions/SyntaxHighlight_GeSHi/geshi/docs directory to save a few megabytes.

手順 1: ダウンロード
Use a Git tool to clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SyntaxHighlight_GeSHi.git in the extensions directory of your wiki. For example using the Git command-line tool (from within wiki/extensions/):

If you accidentally do this in the wrong directory, you will need to move clone from the current location to wiki/extensions/, like this:

control.

Or you can use the ExtensionDistributor.

手順 2: インストール
Add this line to the end of your LocalSettings.php:


 * GeSHi installation (optional)

If you didn't put GeSHi in the extensions/SyntaxHighlight_GeSHi/geshi directory, then change the following line in SyntaxHighlight_GeSHi.class.php to suit the path of your geshi.php file

Sometimes you will need to add the absolute path to geshi (/var/www/html/.../geshi/geshi.php)

Here's a shortcut using the PHP dirname function with the magic __FILE__ constant:

設定
If you want the dashed border like for    tags you have to add them again.

Method 1: CSS ファイル

 * This method requires r52346 or higher of this extension.

Add to MediaWiki:Geshi.css, MediaWiki:Monobook.css or MediaWiki:Common.css pages:

This will give all GeSHi output (except for enclose="none") a dashed border almost identical to &lt;pre&gt; in monobook/main.css

Method 2: インライン CSS
You can also edit the SyntaxHighlight_GeSHi.class.php around line 215 (Line 264 in SVN trunk 82481). Look for this:

and change it to:

On a Unix-like system simply type this command in the directory containing "SyntaxHighlight_GeSHi.class.php":

Link to Extension Talk (2008): Extension talk:SyntaxHighlight GeSHi/Archive 2008
 * See also 52346.


 * If you already add the extension to LocalSettings.php before changing this, comment it out via "#" and refresh the page, then remove the # and refresh one more time.

Default DIV Based Rendering
Long strings will cause the page width to blow up when rendered on a web page. The solution to this is to use the enclose="div" tag, this can be enabled by default by editing SyntaxHighlight_GeSHi.class.php near line 156. Look for the following:

and append an else case to the if statement:

バグと制限
You may report bugs by clicking here.

関連項目

 * GeSHiCodeTag - GeSHiを使う別の拡張機能です
 * GeSHi - Generic Syntax Highlighter
 * ASHighlight (MediaWikiはAndre Simonのhighlightユーティリティをサポートします)
 * Geshi includes every component - no additional downloads
 * Include -- yet another source code syntax highlighter
 * SyntaxHighlight GeSHi ParserFunction -- Parser function based alternative, can be used with Semantic MediaWiki
 * GoogleCodePrettify - syntax highlighter that uses Google Code Prettify library.
 * SyntaxHighlighter - syntax highlighter that uses SyntaxHighlighter library.
 * SyntaxHighlight GeSHi remote - a patch to support highlighting text retrieved from a URL.
 * ViewFiles - an extension, dependent on this one, to support highlighting text from files viewed via a special page.