RenderingModule

Version 18.1 by Thomas Mortagne on 2009/04/03 11:50

Rendering Module

This module is in charge of converting textual input in a given syntax into some rendered output. It's used in XWiki notably for rendering pages in XHTML, for performing syntax conversions, for performing page refactorings and to provide users with access to the page's structured information directly inside their wiki pages using one of the supported scripting macros.

Features

  • Parsers for multiple syntaxes
  • Round trip between XWiki Syntax 2.0 and XHTML. This features allows us to have a strong WYSIWYG editor that doesn't loose information when editing wiki pages. It also allows us to import Office documents into XWiki without loosing information.
  • Macro support.
  • Ability to get the result of the parsing as an AST tree (called XDOM) which can then be used to get access to all structured elements from the flat text input.
  • Supports wiki syntax in link labels even for syntaxes that don't support it.
  • Automatic conversion from any of the supported input syntaxes to XWiki Syntax 2.0 or to XHTML.

General Architecture

rendering.png

  • Parser: Parses some textual input in a given syntax and generate a XDOM object which is an AST representing the input into structured blocks.
  • Renderer: Takes a XDOM as input and generates some output.
  • Transformation: Takes some XDOM and modifies it to generate modified XDOM. One important Transformation registred by default is the MacroTransformation which looks for all Macro Blocks in the XDOM object and replaces them by blocks generated by the various Macros.
  • Macro: Takes a Macro definition as input and generates XDOM Blocks.

Supported Syntaxes

Input Syntaxes:

Output Syntaxes:

Print all than can be rendered in a simple notepad-like editor: basically print WordBlock/SpecialSymbolBlock/SpaceBlock (generate the link label and print it when the link does not have any). It also provide very basic formatting (like separates paragraph or new lines for lists items).

Example

// Parse xwiki 2.0 syntax
Parser parser = (Parser) componentManager.lookup(Parser.ROLE, "xwiki/2.0");
XDOM xdom = parser.parse(new StringReader("This is **bold** {{code language=\"java\"}}something{{/code}}"));
       
// Run macros
TransformationManager txManager = (TransformationManager) componentManager.lookup(TransformationManager.ROLE);
txManager.performTransformations(xdom, new Syntax(SyntaxType.XWIKI, "2.0"));

// Generate XHTML for example
WikiPrinter printer = new DefaultWikiPrinter();
Listener htmlListener = new XHTMLRenderer(printer);

// Perform the rendering        
xdom.traverse(htmlListener);

assertEquals("<p>This is <strong>bold</strong> <!--startmacro:code|-|language=\"java\"|-|something-->"
   + "<span class=\"box code\">something</span><!--stopmacro--></p>", printer.toString());

Adding a new Syntax

TODO

Adding a new Macro

TODO

Adding a new Transformation

TODO

Get Connected