Confluence 5.4 のサポートは終了しています。
ドキュメントの最新バージョンを確認してください。
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!");
}
Using the Code Block Macro
コード ブロック マクロをページに追加するには、次の手順を実行します。
オートコンプリートでマクロを素早く入力する方法 既存のマクロを編集する方法: マクロのプレースホルダをクリックして、[編集] を選択します。マクロのパラメータが編集可能な場合、マクロのダイアログ ウィンドウが開きます。
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).
パラメーター | 既定 | 説明 |
|---|---|---|
Syntax highlighting | java | 構文をハイライトする言語(または環境)を特定します。既定値は java ですが、下記の言語/環境から選択可能です。
|
タイトル | なし | コードブロックにタイトルを追加します。指定すると、コードブロックの先頭行のヘッダーに表示されます。 |
折りたたむ | false | 選択すると、コード マクロの内容が、アクセス時やリフレッシュ時に折りたたまれます。 |
行番号を表示 | false | 選択すると、コード行の左側に数字が表示されます。 |
最初の行番号 | 1 | 行数を表示を選択すると、この値を最初の行の数字として定義します。 |
テーマ | 既定 | コードブロックの表示に使用するカラーテーマを指定します。テーマの多くは人気の統合開発環境 (IDE)のデフォルトのカラースキームをベースにしています。 既定のテーマConfluence (Default) は、ブランクの背景にブラックとカラーフォントの一般的なものですが、下記の人気のテーマから他のテーマを選択することも可能です。
|
Configuring the Code Block macro
コードブロックマクロを設定すれば、特定の言語とテーマを既定値として使用したり、新しい言語をアップロードしたりできます。既定値のテーマと言語を変更するにはシステム管理者権限が必要です。また、新しい言語をアップロードするにはConfluence 管理者権限が必要です。
サイトにコードブロックの既定の外観を設定するには:
- Choose the cog icon at top right of the screen, then choose Confluence Admin.
- Choose Configure Code Macro.
- [既定のテーマ] と [既定の言語] を選択します。
- 保存を選択します 。
他を指定していない限り、すべての新しいコードブロックに既定のテーマと言語が適用されます。既存のコードブロックは変更されません。
他の言語を追加するには:
- Choose the cog icon at top right of the screen, then choose Confluence Admin.
- Choose Configure Code Macro.
- [新規言語の追加] を選択します。
- 追加する言語ファイルを見つけ、新しい言語の [名前] を入力します (これは言語の選択時に表示されます)。
- 追加を選択します。
Language files must be correctly formatted JavaScript files and adhere to the Custom Brush syntax.
インストールした言語を無効化または削除するには:
- Choose the cog icon at top right of the screen, then choose Confluence Admin.
- アドオンの管理を選択します。
- ユーザーがインストールしたアドオンから、アップロードしたアドオンを検索する - 「~をハイライトするカスタムコード マクロ」のように表示されます
- [アンインストール] または [無効化] を選択します。
言語がコードマクロに表示されなくなります。
コードの例
参照先:

