@Test
  public void testParseTableMultipleRowsAndCOlumns() {
    WikiPageNode wikiPageNode = getWikiPageNode("table-2.creole");

    Assert.assertNotNull(wikiPageNode);

    TableNode tableNode = (TableNode) wikiPageNode.getChildASTNode(0);

    Assert.assertNotNull(tableNode);
    Assert.assertEquals(4, tableNode.getChildASTNodesCount());

    CollectionNode collectionNode = (CollectionNode) tableNode.getChildASTNode(0);

    Assert.assertEquals(4, collectionNode.size());

    for (int i = 0; i < 4; ++i) {
      TableHeaderNode tableHeaderNode = (TableHeaderNode) collectionNode.get(i);

      Assert.assertNotNull(tableHeaderNode);

      UnformattedTextNode unformattedTextNode =
          (UnformattedTextNode) tableHeaderNode.getChildASTNode(0);

      Assert.assertNotNull(unformattedTextNode);
      Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

      unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

      Assert.assertEquals("H" + (i + 1), unformattedTextNode.getContent());
    }

    int count = 1;

    for (int row = 1; row < 4; ++row) {
      collectionNode = (CollectionNode) tableNode.getChildASTNode(row);

      Assert.assertEquals(4, collectionNode.size());

      for (int column = 0; column < 4; ++column) {
        TableDataNode tableDataNode = (TableDataNode) collectionNode.get(column);

        Assert.assertNotNull(tableDataNode);

        UnformattedTextNode unformattedTextNode =
            (UnformattedTextNode) tableDataNode.getChildASTNode(0);

        Assert.assertNotNull(unformattedTextNode);
        Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

        unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

        Assert.assertEquals("C" + count++, unformattedTextNode.getContent());
      }
    }
  }
  @Test
  public void testParseTableOneRowOneColumn() {
    WikiPageNode wikiPageNode = getWikiPageNode("table-1.creole");

    Assert.assertNotNull(wikiPageNode);

    TableNode tableNode = (TableNode) wikiPageNode.getChildASTNode(0);

    Assert.assertNotNull(tableNode);
    Assert.assertEquals(2, tableNode.getChildASTNodesCount());

    CollectionNode collectionNode = (CollectionNode) tableNode.getChildASTNode(0);

    Assert.assertEquals(1, collectionNode.size());

    TableHeaderNode tableHeaderNode = (TableHeaderNode) collectionNode.get(0);

    Assert.assertNotNull(tableHeaderNode);

    UnformattedTextNode unformattedTextNode =
        (UnformattedTextNode) tableHeaderNode.getChildASTNode(0);

    Assert.assertNotNull(unformattedTextNode);
    Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("H1", unformattedTextNode.getContent());

    List<ASTNode> astNodes = tableNode.getChildASTNodes();

    collectionNode = (CollectionNode) astNodes.get(1);

    Assert.assertEquals(1, collectionNode.size());

    TableDataNode tableDataNode = (TableDataNode) collectionNode.get(0);

    Assert.assertNotNull(tableDataNode);

    unformattedTextNode = (UnformattedTextNode) tableDataNode.getChildASTNode(0);

    Assert.assertNotNull(unformattedTextNode);
    Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("C1.1", unformattedTextNode.getContent());
  }
 public void visit(TableDataNode tableDataNode) {
   traverse(tableDataNode.getChildASTNodes(), "<td>", "</td>");
 }
예제 #4
0
 public void visit(TableDataNode tableDataNode) {
   traverse(tableDataNode.getChildASTNodes());
 }