pulldown-cmark-to-cmark icon indicating copy to clipboard operation
pulldown-cmark-to-cmark copied to clipboard

Option to render human-friendly tables

Open Xophmeister opened this issue 8 months ago • 3 comments

When rendering a markdown table, this crate strips all the padding whitespace in table cells and sets the header rule to the same width as the respective header:

|Here is a header|Another header|
|:---------------|:-------------|
|foo|bar|
|quux|baz|
|something really long||

This is valid markdown for representing the table, but it's not very human-friendly. It would be nice if there were an option to have cell whitespace padding and for each column to have a uniform width (i.e., the maximum width of the cells in that column + padding). So we'd get output like this:

| Here is a header      | Another header |
| :-------------------- | :------------- |
| foo                   | bar            |
| quux                  | baz            |
| something really long |                |

These tables are equivalent, but the latter is much easier to read.

Xophmeister avatar Apr 07 '25 10:04 Xophmeister

I think this might not be straightforward as the values it sees are already stripped.

However, it does have a way of accessing the original buffer which would allow figuring out the original whitespaces, which then could be re-added.

Byron avatar Apr 07 '25 11:04 Byron

Is there any need to be faithful to the input, insofar as layout is concerned? My understanding is that the padding whitespace in Markdown tables are semantically inert.

Xophmeister avatar Apr 08 '25 08:04 Xophmeister

I think this is addressed above, but it's worth highlighting here.

This is valid markdown for representing the table, but it's not very human-friendly.

It's one advantage of markdown to read well and look good in editors with ascii-only display, but this is only true for tables that are indented nicely. While cumbersome to do by hand, when the indentation is available, I think there is a lot of value in keeping it.

Byron avatar Apr 08 '25 14:04 Byron