Code Macro

Version 1075.1 by Admin on 2022/08/02 04:17

cogHighlights code
Developed by

XWiki Development Team

0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard

Installable with the Extension Manager


See for the list of all supported languages. If you have a hard time finding the right id for the language, you can look at (Short names).

See also the Highlight Macro.


{{code language=<providedlanguage>}}
... code here...

Parameters definition

NameOptionalAllowed valuesDefault valueDescription
languageyesa stringthe macro tries to determine the syntaxthe language identifier of the provided code snippet. If no language identifier is specified then the macro will try to determine the syntax. To avoid highlight you can use "none" language identifier.
  • plain: the result of the parser
  • linenumbers: add line numbers
plainSince 11.5RC1 The layout to apply to the code.

This macro also support all Box Macro parameters.


It's possible to set some configuration for this macro in the file:

NameOptionalAllowed valuesDefault valueDescription (since 2.4M1)yesa stringdefaultthe name of the Pygments style to use. See for more about styles.


Adding new languages

Anyone can add a new language support by:


{{code language="html"}}



Listing all supported languages

The list is on the Pygments language list. However if you want to dynamically check the list of supported language for the XWiki version used of Pygments, you could put the following in a wiki page, using a user with Programming Rights (and assuming that the Python Macro is installed):

import pygments
from pygments.lexers import get_all_lexers

print "|=Language |=Name |=File Extension |=Mime Types"
for lexer in get_all_lexers():
   print "| ", lexer[0], " | ", ", ".join(lexer[1]), " | ", ", ".join(lexer[2]), " | ", ", ".join(lexer[3])


Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.


Dependencies for this extension (org.xwiki.platform:xwiki-platform-rendering-macro-code 14.6):


Get Connected