@Override public String toHtml(RootNode astRoot) { checkArgNotNull(astRoot, "astRoot"); this.printer.print("<section>"); astRoot.accept(this); this.printer.print("</section>"); return this.printer.getString(); }
@Test public void parseTest() throws IOException { InvocationHandler handler = new InvocationHandler() { int indent = 0; protected void visitChildren(Object proxy, Node node) { for (Node child : node.getChildren()) { child.accept((Visitor) proxy); } } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { for (int i = 0; i < indent; ++i) System.out.print('\t'); final Object n = args[0]; System.out.printf("[%s]", n); IfContext.iF(n, StrongEmphSuperNode.class, sesn) .elseIf(n, ExpLinkNode.class, eln) .elseIf(n, AnchorLinkNode.class, aln) .elseIf(n, VerbatimNode.class, vln) .elseIf(n, RefLinkNode.class, rln); System.out.println(); if (n instanceof Node) { ++indent; visitChildren(proxy, (Node) args[0]); --indent; } return null; } }; final ClassLoader cl = PegdownTest.class.getClassLoader(); final Visitor proxy = (Visitor) Proxy.newProxyInstance(cl, new Class[] {Visitor.class}, handler); final PegDownProcessor p = new PegDownProcessor(ToConfluenceSerializer.extensions()); final RootNode root = p.parseMarkdown(loadResource(FILE)); root.accept(proxy); }
@Test public void serializerTest() throws IOException { final PegDownProcessor p = new PegDownProcessor(ToConfluenceSerializer.extensions()); final RootNode root = p.parseMarkdown(loadResource(FILE)); ToConfluenceSerializer ser = new ToConfluenceSerializer() { @Override protected void notImplementedYet(Node node) { throw new UnsupportedOperationException( String.format("Node [%s] not supported yet. ", node.getClass().getSimpleName())); } }; root.accept(ser); System.out.println(ser.toString()); }