code
Audit
- Macro ID
- code
- Source
- XS
- Type
- Wrapper
- Classification reason
- Wrapper: most of the output is the code the user types, which the macro highlights. The advanced source parameter can take the code from a page, an attachment or a script variable instead, which is a generator use, but a rare one.
- Status
- Reviewed
- Criteria version
- 15.20
- XWiki version
- 18.8.0
- Audit date
- 2026-10-14
- Auditor
- Compared macros
- box html
Sources
Where to gather the information the criteria are checked against, see Gather the sources.
| Other sources specific to this macro |
|---|
|
| Criterion | Result | Notes |
|---|---|---|
| D1 wording | OK | |
| D2 summary | OK | |
| D3 category | KO | minor: only in Formatting, like box, while a user may look for code under Development, where html is. A macro can have several categories since XWiki 14.6, so code could also be in Development. |
| D4 quick-action | KO | Quick Actions finds the macro first for "code" and for the synonym "snippet", through its entry "Code Snippet". The synonyms "highlight", "syntax" and "programming" give no result. The French and German names are "Code", the same as the English one, so no language with a different name can be tested. |
| L1 consistency | OK | compared with box and html. Like html, the Quick Action opens the Edit Macro dialog and the content is typed in its text area; unlike html, the content is optional, since the source parameter can give it instead. The box parameters cssClass, image, title and width are inherited from box. The differences are by design. |
| L2 doc-parameters | KO | the parameters are documented only on the legacy extensions.xwiki.org page, with no page in the new documentation. That page also documents only language, layout and source, and covers cssClass, image, title and width with "This macro also supports all Box Macro parameters". |
| L3 doc-example | OK | the documentation example {{code language="html"}}<html>...</html>{{/code}} is used as the most common example. The first example of the page, {{code language=<providedlanguage>}} , holds a placeholder and cannot be copied as is. |
| I1 pattern | KO | the reference wrapper, warning, is inserted by its Quick Action without a dialog; the "Code Snippet" Quick Action opens the Edit Macro dialog, see I3. |
| I2 zero-config | KO | submitting the Edit Macro dialog with the default values inserts {{code}}{{/code}} , which renders an empty grey box in the editor and in view mode, and {{code/}} renders nothing: the user expects a code block and sees an empty frame. |
| I3 instant | KO | inserting from the Quick Actions menu with "/code" and Enter, entry "Code Snippet", opens the Edit Macro dialog with an empty Content text area; the macro is only inserted after submitting it. |
| I4 cursor | KO | after submitting the dialog, the macro widget is selected and the cursor is not in its content: typed text goes nowhere, and the content cannot be typed in place, see E6. |
| I5 focus | N/A | |
| E1 wysiwyg | OK | |
| E2 errors | KO | invalid values are accepted silently, with no message. For example, {{code language="nosuchlanguage"}}<b>x</b>{{/code}} renders the code without highlighting, {{code width="abc"}}x = 1{{/code}} renders with style="width:abc", and {{code image="missing.png"}}x{{/code}} renders a broken image. An invalid layout and an invalid source, on the other hand, give a message that names the problem, like "Unable to convert value [foo]. Allowed values are (case insensitive) "PLAIN" or "LINENUMBERS"." for layout="foo" . |
| E3 nesting | OK | in a list item and in a table cell the macro is inline, so the multi-line example becomes a span with a background per line instead of a code block, and in the editor the bullet of * {{code language="html"}}<html>...</html>{{/code}} is shown in front of the last line. Inline code is still usable, and saving keeps the source. A list, a table and a box inside its content are shown as text, as expected for code. |
| E4 inline-support | OK | the macro declares inline support and renders as a span inside a sentence, as in Run {{code language="bash"}}mvn clean install{{/code}} now. . |
| E5 empty | KO | the content is never editable in place. The empty macro stays visible as an empty grey box, but one click selects the widget and the cursor never enters it: the content can only be typed in the Edit Macro dialog. |
| E6 inplace | KO | the content is never edited in place: in the editor the code is a read-only widget, and changing it needs the Edit Macro dialog, where it is a plain text area with no code editing support. For example, the most common example {{code language="html"}}<html>...</html>{{/code}} cannot be changed by clicking in the displayed code. XWIKI-19978 asks for it. |
Parameters
| Parameter | C1 clarity | C2 mandatory | C3 defaults | C4 input-assistance | C5 groups | C6 order | C7 alternatives | C8 advanced | C9 technical | C13 constraints | Notes |
|---|---|---|---|---|---|---|---|---|---|---|---|
| $content | OK | OK | N/A | OK | N/A | OK | N/A | N/A | N/A | N/A | C4: a plain text area in the Edit Macro dialog, counted under E6. |
| cssClass | OK | OK | OK | OK | KO | OK | N/A | KO | OK | N/A | C1: "A CSS class to add to the box element" uses technical terms, which fit a styling parameter: describing it another way would only be more confusing. C5, minor: the 8 fields, content included, are all in the single group "Optional parameters", above 7. The same holds for every parameter. C8: a styling parameter that is rarely used, and no common example sets it, but it is not marked as advanced. |
| image | KO | OK | OK | KO | KO | OK | N/A | OK | KO | N/A | C1: the description "the image which is to be displayed in the message box" calls the code block a message box, and does not say what value is expected, an attachment or a URL. C4: a free text field, with no image picker, although the type is a resource reference; a reference to a missing attachment is accepted. C9: inherited from box, and no example sets it: users do not expect an image on a code block, so the field is only noise in the dialog and should be hidden for this macro. |
| language | KO | OK | OK | KO | KO | KO | N/A | OK | OK | N/A | C1, minor: the description "the language identifier (java, python, etc.)" does not say that an empty value detects the language automatically, which is what the empty field means, nor that "none" turns the highlighting off. C4: a free text field, although the accepted values are the fixed list of Pygments languages: the user has to know the identifier, like "html" or "bash", and a wrong one, like "nosuchlanguage", is accepted silently. A select with suggestions could be used. C6: language is the only parameter set in the most common example, but it comes fourth, after Content, CssClass and Image, in alphabetical order. |
| layout | OK | OK | OK | OK | KO | OK | N/A | OK | OK | N/A | C3: the select preselects Plain, the declared default. |
| source | OK | OK | OK | KO | KO | OK | OK | OK | OK | N/A | C4: a free text field for a typed reference, like "page:Page/SubPage" or "attachment:[email protected]", with no page or attachment picker: the user has to know the syntax of the reference. A proper field needs design work, since some types, like "script:", cannot have a picker. C7: source and the content are alternative ways to give the code, the source replacing the content, but the Edit Macro dialog cannot present them as one choice, since only parameters can be part of a feature. A limitation of the macro system, listed in the Cross-macro findings, reported as XWIKI-25456. C9: advanced, and used by realistic examples of the documentation, like highlighting an attachment. |
| title | KO | OK | OK | OK | KO | OK | N/A | OK | OK | N/A | C1: the description "the title which is to be displayed in the message box" calls the code block a message box. It does not say either that the title accepts wiki syntax. C9: no example sets it, but a file name above a snippet is a realistic use. |
| width | OK | OK | OK | OK | KO | OK | N/A | OK | OK | KO | C13: only accepts a CSS length "in px or %", but declares no format: "abc" is accepted by the dialog and output as style="width:abc". |
KOs and tickets
Every KO needs a ticket covering it, see Report the KOs. One ticket can cover several KOs. Known issues filed for this macro are suggested in italics: link them as existing tickets when they cover the KO.
| KO | Criterion | Existing tickets | New tickets |
|---|---|---|---|
| D3 | D3 category | XWIKI-25481 | |
| D4 | D4 quick-action | XWIKI-25444 | |
| L2 | L2 doc-parameters | XINFRA-525 | |
| I1 | I1 pattern | XWIKI-25572 | |
| I2 | I2 zero-config | XWIKI-25572 | |
| I3 | I3 instant | XWIKI-25572 | |
| I4 | I4 cursor | XWIKI-25569 | |
| E2 | E2 errors | XCOMMONS-3847 (partial), XRENDERING-823 (partial), XRENDERING-826 (partial), XWIKI-25561 (partial), XWIKI-25582 (partial) | |
| E5 | E5 empty | XWIKI-19978 | |
| E6 | E6 inplace | XWIKI-19978 | |
| C5:cssClass | C5 groups, cssClass | XWIKI-25482 | |
| C8:cssClass | C8 advanced, cssClass | XWIKI-25482 | |
| C1:image | C1 clarity, image | XWIKI-25481, XWIKI-25561 | |
| C4:image | C4 input-assistance, image | XWIKI-25561 | |
| C5:image | C5 groups, image | XWIKI-25482, XWIKI-25561 | |
| C9:image | C9 technical, image | XWIKI-25482, XWIKI-25561 | |
| C1:language | C1 clarity, language | XWIKI-17167 | |
| C4:language | C4 input-assistance, language | XWIKI-17167 | |
| C5:language | C5 groups, language | XWIKI-17167 | |
| C6:language | C6 order, language | XWIKI-25482 | |
| C5:layout | C5 groups, layout | XWIKI-25482 | |
| C4:source | C4 input-assistance, source | XWIKI-25575 | |
| C5:source | C5 groups, source | XWIKI-25482 | |
| C1:title | C1 clarity, title | XWIKI-25481 | |
| C5:title | C5 groups, title | XWIKI-25482 | |
| C5:width | C5 groups, width | XWIKI-25482 | |
| C13:width | C13 constraints, width | XRENDERING-826 |
Tickets
| Ticket | Origin | KOs covered | KOs partly covered |
|---|---|---|---|
| XWIKI-17167 | Existing | C1:language C4:language C5:language | |
| XWIKI-19978 | Existing | E5 E6 | |
| XCOMMONS-3847 | New | E2 | |
| XRENDERING-823 | New | E2 | |
| XWIKI-25444 | New | D4 | |
| XWIKI-25481 | New | C1:image C1:title D3 | |
| XWIKI-25482 | New | C5:cssClass C5:image C5:layout C5:source C5:title C5:width C6:language C8:cssClass C9:image | |
| XINFRA-525 | New | L2 | |
| XRENDERING-826 | New | C13:width | E2 |
| XWIKI-25561 | New | C1:image C4:image C5:image C9:image | E2 |
| XWIKI-25569 | New | I4 | |
| XWIKI-25572 | New | I1 I3 I2 | |
| XWIKI-25575 | New | C4:source | |
| XWIKI-25582 | New | E2 |
Known issues of this macro
| Issue | Title | Status | Criteria |
|---|---|---|---|
| XRENDERING-773 | Leading and final new lines should not be discarded from inline macro content | Reopened | E4 |
| XWIKI-17167 | Code Macro Edit Dialog Should Better Document Supported Languages | Open | C4 |
| XWIKI-19978 | "Code" Macro Should Support Inline Editing | Open | E6 |
| XWIKI-22210 | Blocks of {{code}} are acting strange | Open | |
| XWIKI-22832 | Display line numbers when editing code macro | Open | E6 |
68 more known issues affect every macro: see the Known issues.
Lucas Charpentier