Prism.js Macro

Last modified by Vincent Massol on 2025/07/09 11:57

cogSyntax highlighting Macro based on Prism.js
TypeJAR
CategoryMacro
Developed by

Vincent Massol

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility

XWiki 16.10.0+

Success

Installable with the Extension Manager

Description

See https://prismjs.com/#supported-languages for the list of all supported languages. 

Usage

The macro can work both in inline mode or standalone mode.

Standalone mode:

{{prism language=<languageid>}}
... code here...
{{/prism}}

Inline mode:

Some content {{prism language=<languageid>}}... code here...{{/prism}} other possible content here

Parameters definition

NameOptionalAllowed valuesDefault valueDescription
languageyesa stringnone, meaning no highlightingThe language identifier of the provided code snippet.
layoutyes
  • plain: The plain code snippet is displayed without any extra layout (no line numbers, etc)
  • linenumbers: Display line numbers
plainThe layout to apply to the code.
sourceyesSee source reference (works the same as the Code Macro)No default valueThe reference of a content to highlight instead of the macro content.

Examples

Java with Line Numbers

Input:

{{prism language="java" layout="linenumbers"}}
@Component
@Named("prism")
@Singleton
public class PrismMacro extends AbstractMacro<PrismMacroParameters>
{
}
{{/prism}}

Result:

java-line-numbers.png

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.

Release Notes

v1.2.1

v1.2

v1.1

v1.0.1

v1.0

Dependencies

Dependencies for this extension (org.xwiki.contrib.prismjs:prismjs-macro 1.2.1):

Get Connected