Confluence 3.5 のサポートは終了しています。
ドキュメントの最新バージョンを確認してください。
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!");
}
On this page:
To insert the Code Block macro into a page using the Macro Browser:
- Open the Confluence page or blog post that you want to edit, then click the Edit button.
- Click the Macro Browser icon on the toolbar. The macro browser window will open.
- Scroll through the list of macros to find the one you want. Alternatively, start typing the macro name into the search box at the top right of the macro browser. Macros with a matching name will appear in the main pane.
- Click the desired macro.
- Set the macro parameters to your requirements. If desired, you can preview these changes by clicking Refresh.
- Click Insert to add the macro onto the page.
You can also insert macros using autocomplete. For more information, see Using Autocomplete in the Rich Text Editor.
Once you've found the code block macro, click 'insert' to add it to your page.
Usage with the Wiki Markup Editor
必要な入力項目 |
表示結果 |
|---|---|
{code}
public static void main(String[] args)
{code}
|
public static void main(String[] args) |
パラメーター
Parameters are options that you can include in Confluence macros to control the content or format of the macro output. The table below lists relevant parameters for this macro.
Parameter names are different in the Macro Browser and in wiki markup. Below we show the Macro Browser parameter names in bold text, and the equivalent wiki markup parameters in (bracketed) text. If we do not show any parameter name for the wiki markup, then you should leave out the parameter name and simply include the parameter value as the first parameter, immediately after the colon (:).
パラメーター |
必須かどうか |
既定 |
説明 |
|---|---|---|---|
Syntax highlighting |
いいえ |
java |
Specifies the language (or environment) for syntax highlighting. The default language is Java but you can also choose from one of the following other languages/environments:
|
Title |
いいえ |
なし |
Adds a title to the code macro. If specified, the title will be displayed in its own row at the top of your code macro box. |
Collapsible |
いいえ |
false |
If true, the code macro's content will be collapsed upon visiting or refreshing the Confluence page. Clicking the 'expand source' link allows you to view this content. |
Show line numbers |
いいえ |
false |
If true, a line number will be shown to the left of each line of code, where each number is incremented by 1. |
First line number |
いいえ |
1 |
When Show line numbers ( |
Theme |
いいえ |
既定 |
Specifies the colour scheme used for displaying your code. Many of these themes are based on the default colour schemes of popular Integrated Development Environments (IDEs). The default theme is Confluence (also known as Default), which is typically black and coloured text on a blank background. However, you can also choose from one of the following other popular themes:
|
Be aware that any white space contained between the {code} commands is not manipulated in any way by the Code Block Macro. This is to provide the writer with flexibility over code indentation.
All the optional parameters of the {panel} macro are valid for the {code} macro as well.
例
Example 1: Java
必要な入力項目 |
表示結果 |
|---|---|
{code} |
public String getFoo()
{
return foo;
}
|
Example 2: XML
必要な入力項目 |
表示結果 |
|---|---|
{code:language=XML} |
<test> <another tag="attribute"/> </test> |
関連トピック
Take me back to the Confluence User's Guide.
