Confluence 5.7 のサポートは終了しています。
ドキュメントの最新バージョンを確認してください。
The Code Block macro allows you to display source code in your document with the appropriate syntax highlighting. The code block displays on the page as shown below:
public static void main(String[] args)
{
System.out.println("Hello World!");
}
コード ブロック マクロをページに追加するには、次の手順を実行します。
Speeding up macro entry with autocomplete: Type { and the beginning of the macro name, to see a list of suggested macros. Details are in Using Autocomplete. 既存のマクロを編集する方法: マクロのプレースホルダをクリックして、[編集] を選択します。マクロのパラメータが編集可能な場合、マクロのダイアログ ウィンドウが開きます。
You type the code block directly into the macro placeholder in the editor. Note that any white space contained in the placeholder is not manipulated in any way by the Code Block macro. This is to provide the writer with flexibility over code indentation.
Parameters are options that you can set to control the content or format of the macro output. Where the parameter name used in Confluence storage format or wikimarkup is different to the label used in the macro browser, it will be listed below in brackets (example).
パラメーター | 既定 | 説明 |
|---|---|---|
シンタックス ハイライト | java | 構文をハイライトする言語(または環境)を特定します。既定値は java ですが、下記の言語/環境から選択可能です。
|
タイトル | なし | コードブロックにタイトルを追加します。指定すると、コードブロックの先頭行のヘッダーに表示されます。 |
折りたたみ可能 | false | 選択すると、コード マクロの内容が、アクセス時やリフレッシュ時に折りたたまれます。 |
行番号を表示 | false | 選択すると、コード行の左側に数字が表示されます。 |
最初の行番号 | 1 | 行数を表示を選択すると、この値を最初の行の数字として定義します。 |
テーマ | 既定 | コードブロックの表示に使用するカラーテーマを指定します。テーマの多くは人気の統合開発環境 (IDE)のデフォルトのカラースキームをベースにしています。 既定のテーマConfluence (Default) は、ブランクの背景にブラックとカラーフォントの一般的なものですが、下記の人気のテーマから他のテーマを選択することも可能です。
|
コードブロックマクロを設定すれば、特定の言語とテーマを既定値として使用したり、新しい言語をアップロードしたりできます。既定値のテーマと言語を変更するにはシステム管理者権限が必要です。また、新しい言語をアップロードするにはConfluence 管理者権限が必要です。
サイトにコードブロックの既定の外観を設定するには:
他を指定していない限り、すべての新しいコードブロックに既定のテーマと言語が適用されます。既存のコードブロックは変更されません。
他の言語を追加するには:
Language files must be correctly formatted JavaScript files and adhere to the Custom Brush syntax.
インストールした言語を無効化または削除するには:
言語がコードマクロに表示されなくなります。
次の例は、Confluence ページの基本的なマークアップを調べたり、編集したりする上級ユーザー向けに提供されています。
マクロ名: code
マクロ本文:プレーンテキストをアクセプトする
以下の例ではすべてのパラメータと本文を表示しています。
<ac:structured-macro ac:name="code"> <ac:parameter ac:name="title">This is my title</ac:parameter> <ac:parameter ac:name="theme">FadeToGrey</ac:parameter> <ac:parameter ac:name="linenumbers">true</ac:parameter> <ac:parameter ac:name="language">xml</ac:parameter> <ac:parameter ac:name="firstline">0001</ac:parameter> <ac:parameter ac:name="collapse">true</ac:parameter> <ac:plain-text-body><![CDATA[<b>This is my code</b>]]></ac:plain-text-body> </ac:structured-macro>
下記の 3 例はさまざまなオプションのパラメータを使用したコードブロック マクロの例です。
説明 | Markup | 表示結果 |
|---|---|---|
| 本文にコードブロック マクロ、オプションのパラメータなし | <ac:structured-macro ac:name="code"> <ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body> </ac:structured-macro> | this is my code |
| 本文にコードブロック マクロ、オプションの言語パラメータが定義されている | <ac:structured-macro ac:name="code"> <ac:parameter ac:name="language">html/xml</ac:parameter> <ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body> </ac:structured-macro> | this is my code |
本文にコードブロック マクロとオプションのタイトル、行数、言語パラメータが定義されている | <ac:structured-macro ac:name="code"> <ac:parameter ac:name="title">This is my title</ac:parameter> <ac:parameter ac:name="linenumbers">true</ac:parameter> <ac:parameter ac:name="language">html/xml</ac:parameter> <ac:plain-text-body><![CDATA[this is my code]]></ac:plain-text-body> </ac:structured-macro> | This is my title this is my code |
{code:title=This is my title|theme=FadeToGrey|linenumbers=true|language=html/xml|firstline=0001|collapse=true}
これは私のコードです
{code}