private String renderWikiSyntax ( String content , Transformation transformation , MacroTransformationContext context ) throws MacroExecutionException { String xhtml ; try { // Parse the wiki syntax XDOM xdom = this . contentParser . parse ( content , context , false , false ) ; // Force clean=false for sub HTML macro: // - at this point we don't know the context of the macro, it can be some <div> directly followed by the // html macro, it this case the macro will be parsed as inline block // - by forcing clean=false, we also make the html macro merge the whole html before cleaning so the cleaner // have the chole context and can clean better List < MacroBlock > macros = xdom . getBlocks ( MACROBLOCKMATCHER , Axes . DESCENDANT ) ; for ( MacroBlock macro : macros ) { if ( "html" . equals ( macro . getId ( ) ) ) { macro . setParameter ( "clean" , "false" ) ; } } MacroBlock htmlMacroBlock = context . getCurrentMacroBlock ( ) ; MacroMarkerBlock htmlMacroMarker = new MacroMarkerBlock ( htmlMacroBlock . getId ( ) , htmlMacroBlock . getParameters ( ) , htmlMacroBlock . getContent ( ) , xdom . getChildren ( ) , htmlMacroBlock . isInline ( ) ) ; // Make sure the context XDOM contains the html macro content htmlMacroBlock . getParent ( ) . replaceChild ( htmlMacroMarker , htmlMacroBlock ) ; try { // Execute the Macro transformation ( ( MutableRenderingContext ) this . renderingContext ) . transformInContext ( transformation , context . getTransformationContext ( ) , htmlMacroMarker ) ; } finally { // Restore context XDOM to its previous state htmlMacroMarker . getParent ( ) . replaceChild ( htmlMacroBlock , htmlMacroMarker ) ; } // Render the whole parsed content as a XHTML string WikiPrinter printer = new DefaultWikiPrinter ( ) ; PrintRenderer renderer = this . xhtmlRendererFactory . createRenderer ( printer ) ; for ( Block block : htmlMacroMarker . getChildren ( ) ) { block . traverse ( renderer ) ; } xhtml = printer . toString ( ) ; } catch ( Exception e ) { throw new MacroExecutionException ( "Failed to parse content [" + content + "]." , e ) ; } return xhtml ; }
Parse the passed context using a wiki syntax parser and render the result as an XHTML string .