Highlight Macro

Last modified by H D on 2024/09/09 00:25

cogProvides code highlighting using Highlight.JS
TypeXAR
Category
Developed by

Vincent Massol

Active Installs74
Rating
1 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

Uses Highlight.JS to highlight code snippets.

Compared to the Code Macro:

  • Pros
    • Much faster on server side
  • Cons
    • Works with Javascript and thus you won't get colorized code in WYSIWYG edit mode (because the editor doesn't load the JavaScript code) or when exporting the page to PDF for example
      • The new in-place WYSIWYG editor loads JavaScript code so this is no longer an issue
      • The new client-side PDF export knows how to export HTML DOM changes done by JavaScript code so not an issue anymore either
    • Less syntaxes supported

Usage

{{highlight language="language id" style="style id"}}
... code snippet here...
{{/highlight}}

where:

Parameter NameMandatory?Description
language idNoThe language of your code snippet (see available languages). If not specified, it's auto-discovered.
style idNoThe style to use (see available styles). Default style is default.

Example

Example with default style:

highlight.png

Example with zenburn style:

highlight2.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). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.3

  • Bugfix: HTML needs to be escaped

v1.2

  • Fixed bug with default style
  • Uses monospace font now

v1.1

  • Improved performance by only loading the JS/CSS for pages using the macro
  • Added support for styles

v1.0

First version

Get Connected