2019-07-01 19:50:33 +03:00
..
2019-07-01 19:50:33 +03:00

Tables extension

This extension adds support for GFM tables.

final Markwon markwon = Markwon.builder(context)
        // create default instance of TablePlugin
        .usePlugin(TablePlugin.create(context))
final TableTheme tableTheme = TableTheme.builder()
        .tableBorderColor(Color.RED)
        .tableBorderWidth(0)
        .tableCellPadding(0)
        .tableHeaderRowBackgroundColor(Color.BLACK)
        .tableEvenRowBackgroundColor(Color.GREEN)
        .tableOddRowBackgroundColor(Color.YELLOW)
        .build();

final Markwon markwon = Markwon.builder(context)
        .usePlugin(TablePlugin.create(tableTheme))
Markwon.builder(context)
        .usePlugin(TablePlugin.create(builder ->
                builder
                        .tableBorderColor(Color.RED)
                        .tableBorderWidth(0)
                        .tableCellPadding(0)
                        .tableHeaderRowBackgroundColor(Color.BLACK)
                        .tableEvenRowBackgroundColor(Color.GREEN)
                        .tableOddRowBackgroundColor(Color.YELLOW)
))

Please note, that by default tables have limitations. For example, there is no support for images inside table cells. And table contents won't be copied to clipboard if a TextView has such functionality. Table will always take full width of a TextView in which it is displayed. All columns will always be of the same width. So, default implementation provides basic functionality which can answer some needs. These all come from the limited nature of the TextView to display such content.

In order to provide full-fledged experience, tables must be displayed in a special widget. Since version 3.0.0 Markwon provides a special artifact markwon-recycler that allows to render markdown in a set of widgets in a RecyclerView. It also gives ability to change display widget form TextView to any other.

final Table table = Table.parse(Markwon, TableBlock);
myTableWidget.setTable(table);

:::tip To take advantage of this functionality and render tables without limitations (including horizontally scrollable layout when its contents exceed screen width), refer to recycler-table module documentation that adds support for rendering TableBlock markdown node inside Android-native TableLayout widget. :::

Theme

Cell padding

Padding inside a table cell

Border color

The color of table borders

Border width

The width of table borders

Odd row background

Background of an odd table row

Even row background

Background of an even table row

Header row background

Background of header table row