XWiki Rendering: A content rendering engine
-
Upload
xwiki -
Category
Technology
-
view
1.138 -
download
4
description
Transcript of XWiki Rendering: A content rendering engine
27 au 29 mars 2013
XWiki Rendering
Vincent Massol XWiki Committer CTO XWiki SAS
!
@vmassolVincent Massol, February 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!
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)
Library Initialization
// Initialize Rendering components and allow getting instances!EmbeddableComponentManager componentManager = !! new EmbeddableComponentManager();!componentManager.initialize(this.getClass().getClassLoader());
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());
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());
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());
27 au 29 mars 2013
Demo Time! !
Build a live preview web site using XWiki Rendering and AngularJS
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!
Q&A
Me
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