"prism" Macro

Last modified by Vincent Massol on 2026/10/20 16:30

Reference

Description

The prism macro displays code with syntax highlighting, using Prism.js. In the macro list of the editors it appears as "Prism", in the "Formatting" category.

Usage

{{prism language="<language identifier>"}}
The code to highlight.
{{/prism}}

The content is displayed exactly as written: it isn't parsed as wiki content, and HTML in it is shown as text.

The macro works standalone as well as inline: written on its own it renders a code block, written inside a paragraph it highlights the code inside the sentence.

Parameters

NameMandatoryAllowed ValuesDefault ValueDescription
contentnotext""The code to highlight. Ignored when source is set.
languagenoa Prism.js language identifiernoneThe language of the code. none or an identifier Prism.js doesn't know displays the code without highlighting.
layoutnoplain, linenumbersplainlinenumbers displays line numbers in front of each line. It has no effect inline.
sourcenoscript:<variable>, string:<text>noneThe code to highlight instead of the content: the value of a script variable, or the given text. Works like the source parameter of the Code Macro.

Generated HTML

The macro outputs the following HTML:

  • standalone: <pre><code class="language-<language>">…</code></pre>, with class="line-numbers" on pre for the linenumbers layout;
  • inline: <code class="language-<language>">…</code>.

Examples

Code From a Script Variable

{{velocity}}
#set ($myCode = "SELECT * FROM users WHERE id = 1;")
{{/velocity}}

{{prism language="sql" source="script:myCode"/}}

SQL code read from a Velocity variable and highlighted by Prism.js

Code Inside a Sentence

Call {{prism language="javascript"}}document.querySelector('#main'){{/prism}} to get the main element.

JavaScript code highlighted inside a sentence

FAQ

Why isn't my code highlighted?

Check that the language identifier is one Prism.js supports, and that JavaScript is enabled in the browser: the highlighting is done there.

Related

Get Connected