Extension:SyntaxHighlight/ja

From MediaWiki.org
Jump to: navigation, search
この拡張機能は MediaWiki 1.21 以降にバンドルされています。このため、別途ダウンロードする必要はありません。
MediaWiki 拡張機能マニュアルManual:Extensions
Crystal Clear action run.png
SyntaxHighlight_GeSHi

リリースの状態:Extension status 安定

実装Template:Extension#type Tag
説明Template:Extension#description ウィキページ内でソースコードの構文を強調できるようにする
作者Template:Extension#username Brion Vibber, Tim Starling and Rob Church
最新バージョンTemplate:Extension#version continuous updates
MediaWikiTemplate:Extension#mediawiki 1.24 以降 (MW 1.11 以降と互換性がある古いバージョンもあります)
データベースの変更Template:Extension#needs-updatephp いいえ
ライセンスTemplate:Extension#license GPL-2.0 以降
ダウンロード
README
パラメーターTemplate:Extension#parameters
  • $wgSyntaxHighlightDefaultLang
  • $wgSyntaxHighlightKeywordLinks
タグTemplate:Extension#tags
<syntaxhighlight>
使用するフックTemplate:Extension#hook
ShowRawCssJsManual:Hooks/ShowRawCssJs
ParserFirstCallInitManual:Hooks/ParserFirstCallInit
ExtensionTypesManual:Hooks/ExtensionTypes

translatewiki.net で翻訳を利用できる場合は、SyntaxHighlight 拡張機能の翻訳にご協力ください

使用状況とバージョン マトリクスを確認してください。

問題点Phabricator

未解決のタスク · (GeSHi) バグを報告

SyntaxHighlight GeSHi 拡張機能では、 <syntaxhighlight> タグを使うことにより、ソースコード を表示できます。

この拡張機能では、色を追加します。追加される色の種類は、各コードの(プログラミング)言語の設定に応じた応じた色になります。Like the <pre> tags and the <poem> tags, the tags shows the coding exactly as it was typed, preserving white space.

This extension also can create line numbers.

使用法[edit]

ウィキページ上で, "syntaxhighlight" 要素を使用するには、下記のように記述します:

<syntaxhighlight lang="php">
<?php
    $v = "string";    // sample initialization
?>
html text
<?
    echo $v;         // end of php code
?>
</syntaxhighlight>

を使用すると、結果は:

<?php
    $v = "string";    // sample initialization
?>
html text
<?
    echo $v;         // end of php code
?>

となります。

<source> タグの代替[edit]

rev:50696の前では,本SyntaxHighlightタグと同内容のタグとして <source>タグが利用されていました。. この<source>タグはまだサポートされていますが、 しかし、推奨されていません。 一方、<syntaxhighlight> なら、コード自身に<source>が含まれている場合の(例えば XML など)、衝突を避けることができるので、こちらSyntaxHighlightタグが推奨されています。

パラメーター[edit]

lang="name"
ソースコードで使用しているプログラム言語を指定します。This affects how the extension highlights the source code. 対応プログラム言語は"Supported languages"をご覧ください
line="GESHI_NORMAL_LINE_NUMBERS|GESHI_FANCY_LINE_NUMBERS"
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.
line
Equivalent to line="GESHI_FANCY_LINE_NUMBERS"
line start="n"
Use together with the parameter "line". Define the start number of the line. If you type line start="55", it will start counting at 55, then 56, 57, 58 and so on. Corresponds to start_line_numbers_at method on GeSHi
highlight="n"
強調する行数を指定します。line start="??"は関係ありません
enclose="??"
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.
strict
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.

その他の使用法[edit]

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:

<syntaxhighlight lang="html4strict" line start="100" highlight="5" enclose="div">
HTML module goes here...
</syntaxhighlight>

A typical result is just:

100 <!--This is a comment. Comments are not displayed in the browser-->
101 <table align=center style="background: ivory;color:maroon;font-style:italic;font-family:arial;font-weight:bold;font-size:10pt;"> 
102 <tr><th> Heading 1 </th><th> Heading 2 </th></tr>
103 <tr>
104 <td style="padding:10px;"> This is cell 1 text </td>
105 <td style="padding:10px;"> This is cell 2 text </td>
106 </tr>
107 </table>

対応言語[edit]

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. <syntaxhighlight lang="-"></syntaxhighlight>) might not be the most recent version; see bugzilla: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.

コード 言語
abap ABAP
actionscript ActionScript
ada Ada
apache Apache Configuration
applescript AppleScript
asm アセンブリ言語
asp Active Server Pages (ASP)
autoit AutoIt
bash Bash
basic4gl Basic4GL
bf Brainfuck
blitzbasic Blitz BASIC
bnf バッカス・ナウア記法
c C 言語
c_mac C (Mac)
caddcl AutoCAD DCL
cadlisp AutoLISP
cfdg CFDG
cfm ColdFusion Markup Language
cil 共通中間言語 (CIL)
cobol COBOL
cpp-qt C++ (Qt ツールキット)
cpp C++
csharp C#
css カスケーディング スタイル シート (CSS)
d D 言語
delphi Delphi
diff Diff
div DIV
dos DOS バッチファイル
dot DOT 言語
eiffel Eiffel
fortran Fortran
freebasic FreeBASIC
gambas Gambas
genero Genero
gettext GNU internationalization (i18n) library
glsl OpenGL Shading Language (GLSL)
gml Game Maker Language (GML)
gnuplot gnuplot
groovy Groovy
haskell Haskell
hq9plus HQ9+
html4strict HTML
html5 HTML5
idl Uno IDL
ini INI
inno Inno
intercal INTERCAL
io Io
java Java
java5 Java(TM) 2 Platform Standard Edition 5.0
javascript JavaScript
kixtart KiXtart
klonec Klone C
klonecpp Klone C++
latex LaTeX
lisp Lisp
lolcode LOLCODE
lotusscript LotusScript
lua Lua
コード 言語
m68k Motorola 68000 Assembler
make make
matlab MATLAB M
mirc mIRC scripting language
mxml MXML
mpasm Microchip Assembler
mysql MySQL
nsis Nullsoft Scriptable Install System (NSIS)
objc Objective-C
ocaml-brief OCaml
ocaml OCaml
oobas OpenOffice.org Basic
oracle8 Oracle 8 SQL
oracle11 Oracle 11 SQL
pascal Pascal
per per
perl Perl
php-brief PHP
php PHP
pixelbender Pixel Bender
plsql PL/SQL
povray Persistence of Vision Raytracer
powershell Windows PowerShell
progress OpenEdge Advanced Business Language
prolog Prolog
providex ProvideX
python Python
qbasic QBasic/QuickBASIC
rails Rails
reg Windows Registry
robots robots.txt
rsplus R
ruby Ruby
sas SAS
scala Scala
scheme Scheme
scilab Scilab
sdlbasic SdlBasic
smalltalk Smalltalk
smarty Smarty
sql SQL
tcl Tcl
teraterm Tera Term
text Plain text
thinbasic thinBasic
tsql Transact-SQL
typoscript TypoScript
vala Vala
vb Visual Basic
vbnet Visual Basic .NET
verilog Verilog
vhdl VHDL
vim Vimscript
visualfoxpro Visual FoxPro
visualprolog Visual Prolog
whitespace Whitespace
winbatch Winbatch
xml XML
xorg_conf Xorg.conf
xpp X++
z80 ZiLOG Z80 Assembler

追加機能[edit]

既定のソース言語[edit]

Added in rev: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:

require_once "$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.php";
$wgSyntaxHighlightDefaultLang = "c";

インストール[edit]

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.

注記:

  • 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: ダウンロード[edit]

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/):

git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SyntaxHighlight_GeSHi.git

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

mv SyntaxHighlight_GeSHi /path/to//wiki/extensions/

control.

Or you can use the ExtensionDistributor.

手順 2: インストール[edit]

Add this line to the end of your LocalSettings.php:

require_once "$IP/extensions/SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.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

require "geshi/geshi.php";

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:

require (dirname(__FILE__).'/geshi/geshi.php');

設定[edit]

If you want the dashed border like for <pre> tags you have to add them again.

Method 1: CSS ファイル[edit]

This method requires r52346 or higher of this extension.

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

div.mw-geshi {
  padding: 1em; 
  margin: 1em 0; 
  border: 1px dashed #2f6fab;
  background-color: #f9f9f9;
}

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

Method 2: インライン CSS[edit]

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

$css[] = "\tline-height: normal; border: 0px none white;";

and change it to:

$css[] = "\tline-height: normal; border: 1px dashed #2f6fab;";

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

sed -i 's/$css\[\] = "\\tline-height: normal; border: 0px none white;";/
<!!!continued... THE LINE ABOVE AND THE LINE BELOW ARE ALL ONE LINE!> 
$css\[\] = "\\tline-height: normal; border: 1px dashed #2f6fab;";/g' \
SyntaxHighlight_GeSHi.class.php

Link to Extension Talk (2008): Extension talk:SyntaxHighlight GeSHi/Archive 2008#Problem with CSS: Default style for pre is overwritten

See also rev: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[edit]

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:

...
if ( isset( $args['enclose'] ) ) {
  if ( $args['enclose'] === 'div' ) {
    $enclose = GESHI_HEADER_DIV;
  } elseif ( $args['enclose'] === 'none' ) {
    $enclose = GESHI_HEADER_NONE;
  }
}
...

and append an else case to the if statement:

...
if ( isset( $args['enclose'] ) ) {
  if ( $args['enclose'] === 'div' ) {
    $enclose = GESHI_HEADER_DIV;
  } elseif ( $args['enclose'] === 'none' ) {
    $enclose = GESHI_HEADER_NONE;
  }
} else {
  $enclose = GESHI_HEADER_DIV;
}
...

バグと制限[edit]

You may report bugs by clicking here.

関連項目[edit]


言語:Project:Language policy English  • Deutsch • 日本語 • русский