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

Markdown tables with narrow columns don't render #295

Closed
hugovk opened this issue Apr 2, 2024 · 0 comments · Fixed by #296
Closed

Markdown tables with narrow columns don't render #295

hugovk opened this issue Apr 2, 2024 · 0 comments · Fixed by #296
Labels
bug Something isn't working

Comments

@hugovk
Copy link
Member

hugovk commented Apr 2, 2024

What did you do?

Create a Markdown table with max zero, one or two characters in a column.

What did you expect to happen?

Table to render.

What actually happened?

Just the code was shown.

What versions are you using?

  • Python: 3.12
  • PrettyTable: 3.10.0 and main.

Please include code that reproduces the issue.

The best reproductions are self-contained scripts with minimal dependencies.

from prettytable import PLAIN_COLUMNS, PrettyTable, MARKDOWN

table = PrettyTable()
table.set_style(MARKDOWN)
table.add_row([1, "Adelaide", 1295, 1158259, 600.5])
table.add_row([2, "Brisbane", 5905, 1857594, 1146.4])
table.add_row([3, "Darwin", 112, 120900, 1714.7])
table.add_row([4, "Hobart", 1357, 205556, 619.5])
table.add_row([5, "Sydney", 2058, 4336374, 1214.8])
table.add_row([6, "Melbourne", 1566, 3806092, 646.9])
table.add_row([7, "Perth", 5386, 1554769, 869.4])

for first_header in ("", "A", "AB", "ABC"):
    table.field_names = [first_header, "City name", "Area", "Population", "Annual Rainfall"]
    print(table)
    print()

3.9.0

Before using GFM from #268, all render:

|   | City name | Area | Population | Annual Rainfall |
|:-:|:---------:|:----:|:----------:|:---------------:|
| 1 |  Adelaide | 1295 |  1158259   |      600.5      |
| 2 |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3 |   Darwin  | 112  |   120900   |      1714.7     |
| 4 |   Hobart  | 1357 |   205556   |      619.5      |
| 5 |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6 | Melbourne | 1566 |  3806092   |      646.9      |
| 7 |   Perth   | 5386 |  1554769   |      869.4      |

| A | City name | Area | Population | Annual Rainfall |
|:-:|:---------:|:----:|:----------:|:---------------:|
| 1 |  Adelaide | 1295 |  1158259   |      600.5      |
| 2 |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3 |   Darwin  | 112  |   120900   |      1714.7     |
| 4 |   Hobart  | 1357 |   205556   |      619.5      |
| 5 |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6 | Melbourne | 1566 |  3806092   |      646.9      |
| 7 |   Perth   | 5386 |  1554769   |      869.4      |

| AB | City name | Area | Population | Annual Rainfall |
|:--:|:---------:|:----:|:----------:|:---------------:|
| 1  |  Adelaide | 1295 |  1158259   |      600.5      |
| 2  |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3  |   Darwin  | 112  |   120900   |      1714.7     |
| 4  |   Hobart  | 1357 |   205556   |      619.5      |
| 5  |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6  | Melbourne | 1566 |  3806092   |      646.9      |
| 7  |   Perth   | 5386 |  1554769   |      869.4      |

| ABC | City name | Area | Population | Annual Rainfall |
|:---:|:---------:|:----:|:----------:|:---------------:|
|  1  |  Adelaide | 1295 |  1158259   |      600.5      |
|  2  |  Brisbane | 5905 |  1857594   |      1146.4     |
|  3  |   Darwin  | 112  |   120900   |      1714.7     |
|  4  |   Hobart  | 1357 |   205556   |      619.5      |
|  5  |   Sydney  | 2058 |  4336374   |      1214.8     |
|  6  | Melbourne | 1566 |  3806092   |      646.9      |
|  7  |   Perth   | 5386 |  1554769   |      869.4      |
City name Area Population Annual Rainfall
1 Adelaide 1295 1158259 600.5
2 Brisbane 5905 1857594 1146.4
3 Darwin 112 120900 1714.7
4 Hobart 1357 205556 619.5
5 Sydney 2058 4336374 1214.8
6 Melbourne 1566 3806092 646.9
7 Perth 5386 1554769 869.4
A City name Area Population Annual Rainfall
1 Adelaide 1295 1158259 600.5
2 Brisbane 5905 1857594 1146.4
3 Darwin 112 120900 1714.7
4 Hobart 1357 205556 619.5
5 Sydney 2058 4336374 1214.8
6 Melbourne 1566 3806092 646.9
7 Perth 5386 1554769 869.4
AB City name Area Population Annual Rainfall
1 Adelaide 1295 1158259 600.5
2 Brisbane 5905 1857594 1146.4
3 Darwin 112 120900 1714.7
4 Hobart 1357 205556 619.5
5 Sydney 2058 4336374 1214.8
6 Melbourne 1566 3806092 646.9
7 Perth 5386 1554769 869.4
ABC City name Area Population Annual Rainfall
1 Adelaide 1295 1158259 600.5
2 Brisbane 5905 1857594 1146.4
3 Darwin 112 120900 1714.7
4 Hobart 1357 205556 619.5
5 Sydney 2058 4336374 1214.8
6 Melbourne 1566 3806092 646.9
7 Perth 5386 1554769 869.4

3.10 and main

Only the one with "ABC" in the first column renders.

|   | City name | Area | Population | Annual Rainfall |
| : | :-------: | :--: | :--------: | :-------------: |
| 1 |  Adelaide | 1295 |  1158259   |      600.5      |
| 2 |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3 |   Darwin  | 112  |   120900   |      1714.7     |
| 4 |   Hobart  | 1357 |   205556   |      619.5      |
| 5 |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6 | Melbourne | 1566 |  3806092   |      646.9      |
| 7 |   Perth   | 5386 |  1554769   |      869.4      |

| A | City name | Area | Population | Annual Rainfall |
| : | :-------: | :--: | :--------: | :-------------: |
| 1 |  Adelaide | 1295 |  1158259   |      600.5      |
| 2 |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3 |   Darwin  | 112  |   120900   |      1714.7     |
| 4 |   Hobart  | 1357 |   205556   |      619.5      |
| 5 |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6 | Melbourne | 1566 |  3806092   |      646.9      |
| 7 |   Perth   | 5386 |  1554769   |      869.4      |

| AB | City name | Area | Population | Annual Rainfall |
| :: | :-------: | :--: | :--------: | :-------------: |
| 1  |  Adelaide | 1295 |  1158259   |      600.5      |
| 2  |  Brisbane | 5905 |  1857594   |      1146.4     |
| 3  |   Darwin  | 112  |   120900   |      1714.7     |
| 4  |   Hobart  | 1357 |   205556   |      619.5      |
| 5  |   Sydney  | 2058 |  4336374   |      1214.8     |
| 6  | Melbourne | 1566 |  3806092   |      646.9      |
| 7  |   Perth   | 5386 |  1554769   |      869.4      |

| ABC | City name | Area | Population | Annual Rainfall |
| :-: | :-------: | :--: | :--------: | :-------------: |
|  1  |  Adelaide | 1295 |  1158259   |      600.5      |
|  2  |  Brisbane | 5905 |  1857594   |      1146.4     |
|  3  |   Darwin  | 112  |   120900   |      1714.7     |
|  4  |   Hobart  | 1357 |   205556   |      619.5      |
|  5  |   Sydney  | 2058 |  4336374   |      1214.8     |
|  6  | Melbourne | 1566 |  3806092   |      646.9      |
|  7  |   Perth   | 5386 |  1554769   |      869.4      |

| | City name | Area | Population | Annual Rainfall |
| : | :-------: | :--: | :--------: | :-------------: |
| 1 | Adelaide | 1295 | 1158259 | 600.5 |
| 2 | Brisbane | 5905 | 1857594 | 1146.4 |
| 3 | Darwin | 112 | 120900 | 1714.7 |
| 4 | Hobart | 1357 | 205556 | 619.5 |
| 5 | Sydney | 2058 | 4336374 | 1214.8 |
| 6 | Melbourne | 1566 | 3806092 | 646.9 |
| 7 | Perth | 5386 | 1554769 | 869.4 |

| A | City name | Area | Population | Annual Rainfall |
| : | :-------: | :--: | :--------: | :-------------: |
| 1 | Adelaide | 1295 | 1158259 | 600.5 |
| 2 | Brisbane | 5905 | 1857594 | 1146.4 |
| 3 | Darwin | 112 | 120900 | 1714.7 |
| 4 | Hobart | 1357 | 205556 | 619.5 |
| 5 | Sydney | 2058 | 4336374 | 1214.8 |
| 6 | Melbourne | 1566 | 3806092 | 646.9 |
| 7 | Perth | 5386 | 1554769 | 869.4 |

| AB | City name | Area | Population | Annual Rainfall |
| :: | :-------: | :--: | :--------: | :-------------: |
| 1 | Adelaide | 1295 | 1158259 | 600.5 |
| 2 | Brisbane | 5905 | 1857594 | 1146.4 |
| 3 | Darwin | 112 | 120900 | 1714.7 |
| 4 | Hobart | 1357 | 205556 | 619.5 |
| 5 | Sydney | 2058 | 4336374 | 1214.8 |
| 6 | Melbourne | 1566 | 3806092 | 646.9 |
| 7 | Perth | 5386 | 1554769 | 869.4 |

ABC City name Area Population Annual Rainfall
1 Adelaide 1295 1158259 600.5
2 Brisbane 5905 1857594 1146.4
3 Darwin 112 120900 1714.7
4 Hobart 1357 205556 619.5
5 Sydney 2058 4336374 1214.8
6 Melbourne 1566 3806092 646.9
7 Perth 5386 1554769 869.4

The difference is that before, there was at least one hyphen in the row under the first column. But after there is not. We should make sure there is at least one hyphen.

@hugovk hugovk added the bug Something isn't working label Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant