jazzband / prettytable

Display tabular data in a visually appealing ASCII table format
https://pypi.org/project/PrettyTable/
Other
1.35k stars 154 forks source link

Adjusting markdown table formatting to comply with GitHub flavored markdown specification #251

Closed estyxx closed 8 months ago

estyxx commented 1 year ago

Is your feature request related to a problem? Please describe.

When using prettytable to generate tables in the Markdown format, I've observed that the line separating the headers from the table body doesn't follow the standard GitHub Flavored Markdown Spec. In the GitHub spec, there are spaces before and after the colons (:), like so:

| :---- | :---------------------------------------- | -------: |

However, prettytable generates the line without these spaces:

|:-------|:-------------------------------------------|----------:|

Describe the solution you'd like

I propose that prettytable be adjusted to adhere to the GitHub Flavored Markdown Spec for tables, which includes having spaces before and after the colons in the line separating headers from the table body.

Describe alternatives you've considered

A possible alternative could be to reformat the generated tables manually, but this is not an efficient solution, especially when dealing with larger tables or multiple instances. It would be much more convenient and efficient for the formatting to be correct upon generation.

Additional context

This formatting discrepancy can lead to inconsistencies when the tables are rendered in different Markdown parsers that strictly follow the GitHub Flavored Markdown Spec, which could affect the readability of the tables. Having prettytable adhere to this spec would eliminate such issues.

hugovk commented 1 year ago

Sounds reasonable, would you like to put together a PR?


As an aside, interesting to see the GFM spec doesn't say that spaces should be part of the delimiter row:

The delimiter row consists of cells whose only content are hyphens (-), and optionally, a leading or trailing colon (:), or both, to indicate left, right, or center alignment respectively.

And the only mention of spaces:

Spaces between pipes and cell content are trimmed.

But the examples clearly do include spaces.

I wonder if other Markdown variants are different? At least https://michelf.ca/projects/php-markdown/extra/#table also has spaces in the examples, and anyway, GFM is definitely a popular one.

firai commented 1 year ago

At least https://michelf.ca/projects/php-markdown/extra/#table also has spaces in the examples

By the way, the one example in Markdown Extra with a colon actually doesn't have a space after the colon, unlike the other examples without colons. However, both GFM and MultiMarkdown show spaces before and after colons.