Skip to content

Adjustable final column width setting #22

@eread

Description

@eread

At the moment, MarkdownTableFormatter formats Markdown tables so that the final or right-most column is as wide as the widest content.

Having configurable options for the cells in the right-most column would be useful.

For example, a setting could be added so that if the data in a cell in the right-most column:

  • Is narrower than or the same width as the header, the cell width matches the header width.
  • Is wider than the header, the cell is as wide as the content.

If you assume that a table in a Markdown file is already formatted this way, a setting like this would allow adding wide rows to the table and using the MarkdownTableFormatter package without the possibility that an entire table would be reformatted.

For pure readability, the current behavior makes sense. However, in Git-based systems with diff views where Markdown is often authored, reformatting the entire table for additional rows makes less sense.

Example

This is an example table using the current behavior:

| Column 1       | Column 2       | Column 3       |
|:---------------|:---------------|:---------------|
| Row 1          | Row 1          | Row 1          |
| Row 2          | Row 2          | Row 2          |
| Row 3 is wider | Row 3 is wider | Row 3 is wider |
| Row 4          | Row 4          | Row 4          |

This is what a table would look like if the new setting was available:

| Column 1       | Column 2       | Column 3 |
|:---------------|:---------------|:---------|
| Row 1          | Row 1          | Row 1    |
| Row 2          | Row 2          | Row 2    |
| Row 3 is wider | Row 3 is wider | Row 3 is wider |
| Row 4          | Row 4          | Row 4    |

Imagine you wanted to add the following row:

| Row 5 | Row 5 | Row 5 with a really wide cell |

With the existing behavior, the entire table becomes:

| Column 1       | Column 2       | Column 3                      |
|:---------------|:---------------|:------------------------------|
| Row 1          | Row 1          | Row 1                         |
| Row 2          | Row 2          | Row 2                         |
| Row 3 is wider | Row 3 is wider | Row 3 is wider                |
| Row 4          | Row 4          | Row 4                         |
| Row 5          | Row 5          | Row 5 with a really wide cell |

That triggers a change on every row.

With the new setting, the table would be:

| Column 1       | Column 2       | Column 3 |
|:---------------|:---------------|:---------|
| Row 1          | Row 1          | Row 1    |
| Row 2          | Row 2          | Row 2    |
| Row 3 is wider | Row 3 is wider | Row 3 is wider |
| Row 4          | Row 4          | Row 4    |
| Row 5          | Row 5          | Row 5 with a really wide cell |

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions