Skip to content

Tables Extension

Vladimir Schneider edited this page Oct 19, 2019 · 4 revisions

flexmark-java extension for table processing

Overview

Enables tables using pipes as in GitHub Flavored Markdown. With added options to handle column span syntax, ability to have more than one header row, disparate column numbers between rows, etc.

Converts pipe | delimited text to table elements:

|    Heading Centered    | Heading Left Aligned   |  Heading Centered  |   Heading Right Aligned |
|------------------------|:-----------------------|:------------------:|------------------------:|
| Cell text left aligned | Cell text left aligned | Cell text centered | Cell text right aligned |
| cell 21                | cell 22                |      cell 22       |                 cell 22 |

Syntax

If GitHub table rendering option is not selected then tables can have multiple header rows, number of columns in table body does not need to match header or separator line columns and column spans can be specified by adding consecutive | at the end of the cell. Each pipe represents column span count || spans two columns, ||| three, etc.

When column span syntax is enabled, empty table cells must have at least one space. Otherwise they will be interpreted as column spans for the previous cell.

Note that this extended syntax is not supported by GitHub.

⚠️ Table elements must be preceded by a blank line to be processed by this extension.

Parsing Details

Use class TablesExtension in artifact flexmark-ext-tables.

The following options are available:

Defined in TablesExtension class:

Static Field Default Value Description
MIN_HEADER_ROWS 0 minimum number of header rows
MAX_HEADER_ROWS Integer.MAX_INTEGER maximum number of header rows
HEADER_SEPARATOR_COLUMN_MATCH false when true only tables whose header lines contain the same number of columns as the separator line will be recognized
APPEND_MISSING_COLUMNS false whether table body columns should be at least the number or header columns
DISCARD_EXTRA_COLUMNS false whether to discard body columns that are beyond what is defined in the header
COLUMN_SPANS true treat consecutive pipes at the end of a column as defining spanning column.
WITH_CAPTION true when true will parse table caption line, line after table with format [ ... ]
CLASS_NAME `` class name to use on tables
FORMAT_TABLE_LEAD_TRAIL_PIPES true formatting option when enabled adds opening and closing pipes on table rows, see: Markdown Formatter
FORMAT_TABLE_SPACE_AROUND_PIPES true formatting option when enabled adds space around cell text, see: Markdown Formatter
FORMAT_TABLE_ADJUST_COLUMN_WIDTH true expand columns to align column pipes across rows, formatting option see: Markdown Formatter
FORMAT_TABLE_APPLY_COLUMN_ALIGNMENT true when true and FORMAT_TABLE_ADJUST_COLUMN_WIDTH is true then apply column alignment to cell text, formatting option see: Markdown Formatter
FORMAT_TABLE_FILL_MISSING_COLUMNS false when true add columns to make all rows have same number of columns, formatting option see: Markdown Formatter
FORMAT_TABLE_CAPTION false when true table caption is removed, formatting option when enabled removes table caption, see: Markdown Formatter
FORMAT_TABLE_LEFT_ALIGN_MARKER DiscretionaryText.AS_IS how to handle the left align : in output, formatting option see: Markdown Formatter
FORMAT_TABLE_MIN_SEPARATOR_COLUMN_WIDTH 3 minimum separator column in formatted output
FORMAT_TABLE_MIN_SEPARATOR_DASHES 1 minimum separator dashes in formatted output
FORMAT_TABLE_TRIM_CELL_WHITESPACE true trim table cell whitespace in formatted output
FORMAT_TABLE_CAPTION_SPACES DiscretionaryText.AS_IS how to handle spaces after [ and before ] in formatted output
FORMAT_TABLE_INDENT_PREFIX "" adds arbitrary prefix to tables in formatted output
FORMAT_TABLE_MANIPULATOR TableManipulator.NULL interface invoked before table is appended to formatted output. Allows table manipulation
FORMAT_CHAR_WIDTH_PROVIDER CharWidthProvider.NULL interface used to provide actual characters widths so table formatting can take these into account
TRIM_CELL_WHITESPACE true false will leave surrounding spaces as part of the cell text
MIN_SEPARATOR_DASHES 3 minimum number of - or : characters in a table separator column
  • DiscretionaryText
    • AS_IS: no change
    • ADD: add to columns which have no alignment
    • REMOVE: remove from columns which have left alignment

When used with Formatter renderer with default options will convert:

day|time|spent
:---|:---:|--:
nov. 2. tue|10:00|4h 40m
nov. 3. thu|11:00|4h
nov. 7. mon|10:20|4h 20m
total:|| **13h**

to

| day         | time  |   spent |
|:------------|:-----:|--------:|
| nov. 2. tue | 10:00 |  4h 40m |
| nov. 3. thu | 11:00 |      4h |
| nov. 7. mon | 10:20 |  4h 20m |
| total:             || **13h** |