@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);
  }
Example #2
0
 @Override
 public String toHtml(RootNode astRoot) {
   checkArgNotNull(astRoot, "astRoot");
   this.printer.print("<section>");
   astRoot.accept(this);
   this.printer.print("</section>");
   return this.printer.getString();
 }
 private void extractHeader(RootNode rootNode) {
   List<Node> children = rootNode.getChildren();
   PageHeaderNode headerNode = findHeaderNode(rootNode);
   children.clear();
   if (headerNode != null) {
     children.addAll(headerNode.getChildren());
   }
 }
  @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());
  }
 @Override
 public void visit(@NotNull RootNode node) {
   node.getReferences().forEach(this::visitChildren);
   node.getAbbreviations().forEach(this::visitChildren);
   visitChildren(node);
 }