com.overzealous.remark.util
Class MarkdownTable

java.lang.Object
  extended by com.overzealous.remark.util.MarkdownTable

public class MarkdownTable
extends Object

Provides a class to contain the structure of an HTML table so it can be cleanly formatted as a plain text structure (either as Markdown or within a Markdown code block).

Author:
Phil DeJarnett

Nested Class Summary
static class MarkdownTable.Alignment
          Simple enum to manage the alignment of a column.
 
Constructor Summary
MarkdownTable()
          Creates a new, empty MarkdownTable
 
Method Summary
 List<MarkdownTableCell> addBodyRow()
          Creates a new body row, and returns it so it can have cells added to it.
 List<MarkdownTableCell> addHeaderRow()
          Creates a new header row, and returns it so it can have cells added to it.
 int getNumberOfColumns()
          Returns the total number of columns in this table.
 void renderTable(PrintWriter output, boolean allowColspan, boolean renderAsCode)
          Renders out the final table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkdownTable

public MarkdownTable()
Creates a new, empty MarkdownTable

Method Detail

addHeaderRow

public List<MarkdownTableCell> addHeaderRow()
Creates a new header row, and returns it so it can have cells added to it.

Returns:
A list that can have columns added to it.

addBodyRow

public List<MarkdownTableCell> addBodyRow()
Creates a new body row, and returns it so it can have cells added to it.

Returns:
A list that can have columns added to it.

renderTable

public void renderTable(PrintWriter output,
                        boolean allowColspan,
                        boolean renderAsCode)
Renders out the final table. This process starts by calculating widths and alignment for the columns. The final output should be nicely spaced, centered, and look very clean.

Parameters:
output - The writer to receive the final output.
allowColspan - If true, cells that span multiple columns are preserved. If false, they are rendered in their own column, then empty columns are placed after.
renderAsCode - If true, the output is rendered as a code block

getNumberOfColumns

public int getNumberOfColumns()
Returns the total number of columns in this table. This takes into account colspans

Returns:
The total number of columns in this table.


© 2011 OverZealous Creations, LLC - BitBucket Repository