11
27 au 29 mars 2013 XWiki Rendering Vincent Massol XWiki Committer CTO XWiki SAS @vmassol Vincent Massol, February 2014

XWiki Rendering @ FOSDEM 2014

Embed Size (px)

DESCRIPTION

A useful framework for converting content in a given syntax into another syntax. Can be used outside of the rest of XWiki, as a library.

Citation preview

Page 1: XWiki Rendering @ FOSDEM 2014

27 au 29 mars 2013

XWiki Rendering

Vincent Massol XWiki Committer CTO XWiki SAS

!

@vmassolVincent Massol, February 2014

Page 2: XWiki Rendering @ FOSDEM 2014

What is XWiki Rendering?

• A Java, open source (LGPL) library to convert an input in a given syntax into an output in another syntax.

• Needs: Wikis, Commenting system on web sites, any place where you ask user to enter content.

• Complex to implement properly!

Page 3: XWiki Rendering @ FOSDEM 2014

Supported Syntaxes

• XWiki Syntax 1.0, 2.0, 2.1

• HTML 4.x/XHTML 1.0

• Plain text

• Docbook 4.x

• Confluence/Confluence XHTML

• Mediawiki

• JSPWiki

• TWiki

• Creole 1.0

• Markdown

• APT

• XWiki Syntax 2.0, 2.1

• HTML 4.x/XHTML 1.0

• Plain text

• Docbook 4.x

• APT

Input Syntaxes Output Syntaxes

Future Syntaxes• PDF (prototype version using iText exists)

• Asciidoc (need events in Asciidoctor)

Page 4: XWiki Rendering @ FOSDEM 2014

Library Initialization

// Initialize Rendering components and allow getting instances!EmbeddableComponentManager componentManager = !! new EmbeddableComponentManager();!componentManager.initialize(this.getClass().getClassLoader());

Page 5: XWiki Rendering @ FOSDEM 2014

Example 1: Convert to XHTML

Converter converter =!! componentManager.getInstance(Converter.class);!!WikiPrinter printer = new DefaultWikiPrinter();!converter.convert(new StringReader("This is **bold**”),!! Syntax.XWIKI_2_1, Syntax.XHTML_1_0, printer);!!Assert.assertEquals("<p>This is <strong>bold</strong></p>", !! printer.toString());

Page 6: XWiki Rendering @ FOSDEM 2014

Example 2: Italicize linksParser parser = componentManager.getInstance(Parser.class, !! Syntax.XWIKI_2_1.toIdString());!XDOM xdom = parser.parse(new StringReader("This a [[link>MyPage]]"));! !// Find all links and make them italic!for (Block block : xdom.getBlocks(new ClassBlockMatcher(LinkBlock.class), !! Block.Axes.DESCENDANT)) {!! Block parentBlock = block.getParent();!! Block newBlock = new FormatBlock(Collections.<Block>singletonList(block), !! ! Format.ITALIC);!! parentBlock.replaceChild(newBlock, block);!}!!WikiPrinter printer = new DefaultWikiPrinter();!BlockRenderer renderer = componentManager.getInstance(BlockRenderer.class, !! Syntax.XWIKI_2_1.toIdString());!renderer.render(xdom, printer);!!Assert.assertEquals("This a //[[link>MyPage]]//", printer.toString());

Page 7: XWiki Rendering @ FOSDEM 2014

Example 3: Execute Macros

Parser parser = componentManager.getInstance(Parser.class, !! Syntax.XWIKI_2_1.toIdString());!XDOM xdom = parser.parse(new StringReader("{{id name=\"test\"/}}"));!!Transformation transformation = componentManager.getInstance(Transformation.class, !! "macro");!TransformationContext txContext = new TransformationContext(xdom, parser.getSyntax());!transformation.transform(xdom, txContext);!!WikiPrinter printer = new DefaultWikiPrinter();!BlockRenderer renderer = componentManager.getInstance(BlockRenderer.class, !! Syntax.XHTML_1_0.toIdString());!renderer.render(xdom, printer);!!Assert.assertEquals("<div id=\"test\"></div>", printer.toString());

Page 8: XWiki Rendering @ FOSDEM 2014

27 au 29 mars 2013

Demo Time! !

Build a live preview web site using XWiki Rendering and AngularJS

Page 9: XWiki Rendering @ FOSDEM 2014

Use it!

• Documentation on http://rendering.xwiki.org

• WYSIWYG editor using XWiki Rendering also available

• Use Maven for a simple start (recommended) or use the Standalone JAR

• Contribute to add more Syntaxes, more Macros!

Page 10: XWiki Rendering @ FOSDEM 2014

Q&A

Me

Page 11: XWiki Rendering @ FOSDEM 2014

Vincent Massol

• Speaker Bio

• CTO XWiki SAS

• Your Projects

• XWiki (community-driven open source project)

• Past: Maven, Apache Cargo, Apache Cactus, Pattern Testing

• Other Credentials:

• LesCastCodeurs podcast

• Creator of OSSGTP open source group in Paris

• 3 books: JUnit in Action, Maven: A Developer’s Notebook, BBWM