WYSIWYG Editor Module

Last modified by Simon Urli on 2026/11/30 10:02

pencilGeneric API for all WYSIWYG content editors.
TypeJAR
CategoryOther
Developed by

XWiki Development Team

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Success

Installable with the Extension Manager

Description

This module provides a generic API that can be used by any WYSIWYG editor that wants to integrate with XWiki. Besides that, it also publishes a section in the Wiki Administration to configure the default WYSIWYG content editor.

Generic API

This module provides the following APIs:

  • clean HTML coming from a WYSIWYG editor
  • convert between (annotated) HTML and wiki syntax
  • round-trip conversion (go from annotated HTML to wiki syntax and back, which is useful if you want to render the wiki syntax rendering macros)
  • an HTTP filter to convert automatically the value of specific HTTP request parameters from HTML to wiki syntax
  • import content from office attachments
  • a script service ($services.wysiwyg) that exposes most of the above, plus adds support for:
    • checking if a specific wiki syntax can be edited by a WYSIWYG editor
    • retrieving the HTML syntax used by the WYSIWYG editor
    • render a specific page template (the WYSIWYG editor content template)
    • XWiki 18.10.0+ executing the macro calls of the content edited with a WYSIWYG editor whose syntax is not HTML (see the Refresh Service)

Administration Section

The administration section allows administrators to configure the default WYSIWYG content editor, which is useful in case multiple installed extensions provide WYSIWYG content editing capability.

wysiwygEditor-adminSection.png

WYSIWYG Editor Integrations

The following WYSIWYG editor integrations are available:

Conversion Filter

This module provides a servlet request filter that supports converting the content submitted by a WYSIWYG editor, from the syntax used internally by the editor to the syntax used to store the content. For instance the content is normally stored as wiki syntax but the WYSIWYG editor doesn't know how to edit wiki syntax. It knows how to edit HTML, we need to:

  • convert the wiki syntax to HTML before loading the editor, in order to pass the HTML to the editor
  • convert the HTML produced by the editor back to the wiki syntax used to store the edited content in a wiki page

The latter is achieved using the conversion filter: the WYSIWYG editor submits HTML and the conversion filter intercepts the submit request (server-side) and replaces the HTML with the result of converting the HTML to the storage wiki syntax. For this to work the editor needs to send 3 request parameters like this:

fieldName=value
RequiresHTMLConversion=fieldName
fieldName_syntax=xwiki/2.1

Replace "fieldName" with the name of the edited field and replace "xwiki/2.1" with the ID of the storage syntax.

XWiki 17.4.0+

If the WYSIWYG editor doesn't use HTML internally to edit the content, then it needs to submit 4 parameters instead:

fieldName=value
RequiresConversion=fieldName
fieldName_inputSyntax=foo/1.0
fieldName_outputSyntax=xwiki/2.1

Note that an important difference between RequiresHTMLConversion and RequiresConversion is that the former performs some HTML cleanup as well, while the latter simply converts from one syntax to another. So while you can use the second method to convert from HTML to wiki syntax, you must be aware that you lose the cleanup.

Rendering transformations (e.g. macros) are not executed in both cases (RequiresHTMLConversion and RequiresConversion).

Refresh Service

XWiki 18.10.0+

A WYSIWYG editor that doesn't use HTML internally (e.g. BlockNote) can't render the macro calls of the edited content itself. To show the output of the macro calls that are inserted or modified while editing, it sends the edited content to the wysiwyg/refresh template, which executes the macro calls and returns the content with their output, in the syntax of the editor. All the macro calls are executed, not only the modified ones, because the output of a macro call can depend on the rest of the content (e.g. a table of contents).

Send a POST request to the page where the edited content is saved, since it is the context of the macro calls:

POST /xwiki/bin/get/Space/Page?xpage=wysiwyg/refresh

content=...&editorSyntax=blocknote/1.0&sourceSyntax=xwiki/2.1&form_token=...
ParameterDescription
contentThe edited content, in the syntax of the editor.
editorSyntaxRequired. The syntax of the editor (e.g. blocknote/1.0), used to parse the content and to render the result.
sourceSyntaxThe syntax used to save the content (e.g. xwiki/2.1). Defaults to the syntax of the page, which is also used when the given syntax is not valid. The macro content and parameters edited in place are converted to this syntax before the macros are executed, like when the content is saved.
restrictedtrue to execute the macros in a restricted context (e.g. when editing a comment), where unsafe macros such as the script macros are not executed.
form_tokenRequired. The CSRF token.
collaborationThe realtime collaboration session where the content is edited, if any.

The response is the refreshed content, as text/plain. The template answers 403 when the request is not a POST or the CSRF token is not valid, 400 when the editor syntax is missing or not valid, and 500 when the content can't be parsed, the editor syntax has no parser or renderer, or the macro calls can't be executed.

The macro calls are executed with the rights of the current user. When the request names a realtime collaboration session, they are executed with the rights of the participant with the least script rights among those that changed the content, so that a user doesn't execute the scripts inserted by others with their own rights.

The template calls $services.wysiwyg.refresh(content, editorSyntax, sourceSyntax, sourceReference, restricted), which is an unstable API. It requires programming right, because it doesn't execute the content with the rights of the calling script's author.

Configuration

XWiki 17.5.0+

Some properties of this module can be configured through xwiki.properties:

#-------------------------------------------------------------------------------------
# WYSIWYG API
#-------------------------------------------------------------------------------------

#-# [Since 17.5.0]
#-# Define if the type of the macro parameter should be inferred from their default value when no specific type is
#-# indicated to build the macro configuration UI. This is currently used to automatically set the type to Boolean
#-# when a parameter has a default value set to 'true' or 'false' and doesn't define a specific type.
# wysiwyig.inferMacroParameterTypeBasedOnDefaultValue=true

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-wysiwyg-api 18.9.0):

Get Connected