Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
estyxx opened this issue Jul 8, 2023 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@estyxx
Copy link

estyxx commented Jul 8, 2023

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
Copy link
Member

hugovk commented Jul 10, 2023

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
Copy link

firai commented Jul 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

3 participants