Exemplo n.º 1
0
  private Table fixedTable(Rover rover, String rowbreak) {

    String head = rover.group("head");
    String widths = rover.group("widths");
    String rows = rover.group("rows");

    Table table = new Table(markdown);

    String[] splitted = rows.split(rowbreak);
    if (splitted.length == 1) splitted = rows.split("\n");

    table.columns(COLDEF_P, widths);

    if (head != null) {
      table.addHead(head);
    }

    if (!widths.contains(":"))
      if (head != null) table.alignment(head);
      else table.alignment(splitted[0]);

    for (String row : splitted) {
      table.addRow(row);
    }
    rover.next();
    return table;
  }
Exemplo n.º 2
0
  private Table tables(Rover rover) {
    if (rover.at(SIMPLE_TABLE_P) || rover.at(MULTILINE_P)) return fixedTable(rover, "\n\n");

    if (rover.at(GRID_P)) return fixedTable(rover, "\\+(-+\\+)+ *\n");

    if (rover.at(PIPE_P)) return pipeTable(rover);

    return null;
  }
Exemplo n.º 3
0
  private Table pipeTable(Rover rover) {
    String head = rover.group("head");
    String widths = rover.group("widths");
    String rows = rover.group("rows");

    Table table = new Table(markdown);
    String[] splitted = rows.split("\n");

    table.columns(COLDEF_P, widths);

    if (head != null) table.addHead(pipeSplit(head));

    for (String row : splitted) table.addRow(pipeSplit(row));

    rover.next();
    return table;
  }
Exemplo n.º 4
0
  @Override
  public Block process(Rover rover) throws Exception {
    if (rover.at(TABLE_EXT_P) || rover.at(CAPTION_P)) {
      String caption = rover.group("caption");
      rover.next();
      Table table = tables(rover);
      if (table != null) {
        table.setCaption(caption);
        return table;
      }
      rover.error("Table extension found but no table pattern matched");
    } else {
      Table table = tables(rover);
      if (table != null) {
        if (rover.at(CAPTION_P)) {
          table.setCaption(rover.group("caption"));
          rover.consume();
        }
        return table;
      }
    }

    return null;
  }