Code Macro

Version 6.1 by Simon Urli on 2019/06/14 16:47

cogHighlights code
TypeJAR
Category
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Enterprise, XWiki Standard

Installable with the Extension Manager

Description

See http://pygments.org/languages/ for the list of all supported languages. If you have a hard time finding the right id for the language you can look at pygments.org/docs/lexers/.

See also the Highlight Macro.

Usage

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

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.
layoutyes
  • 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.

Configuration

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

NameOptionalAllowed valuesDefault valueDescription
rendering.macro.code.pygments.style (since 2.4M1)yesa stringdefaultthe name of the Pygments style to use. See http://pygments.org/docs/styles/ for more about styles.

Example:

rendering.macro.code.pygments.style=vs

Adding new languages

Anyone can add a new language support by:

Example

{{code language="html"}}
<html>
  <head>Cool!</head>
</html>
{{/code}}

Result

<html>
  <head>Cool!</head>
</html>

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

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

Tags:
    

Get Connected