Class 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
    • 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.