FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add table format "colon_grid" by dn813 · Pull Request #341 · astanin/python-tabulate · GitHub

Add table format "colon_grid" - #341

Merged
astanin merged 5 commits into
astanin:masterfrom
dn813:master
Sep 26, 2024
Merged

Add table format "colon_grid"#341
astanin merged 5 commits into
astanin:masterfrom
dn813:master

Conversation

dn813 commented Sep 26, 2024

Copy link
Copy Markdown

To close #332, this PR adds a new table format "colon_grid" which is the same as the "grid" format but adds colons to the line below the header to indicate a column's alignment. This requires forcing left alignment on the data in the text output of tabulate.

With this format, tabulate can create Pandoc-compatible tables with alignments.

Existing grid format:

+------------+------------+------------+
| Column 1   | Column 2   | Column 3   |
+============+============+============+
| 1          | a          | 1.23       |
+------------+------------+------------+
| 2          | b          | 12.3       |
+------------+------------+------------+
| 3          | c          | 123        |
+------------+------------+------------+

Grid format using existing alignment functionality:

+------------+------------+------------+
|   Column 1 | Column 2   |   Column 3 |
+============+============+============+
|          1 | a          |       1.23 |
+------------+------------+------------+
|          2 | b          |      12.3  |
+------------+------------+------------+
|          3 | c          |     123    |
+------------+------------+------------+

Broken Pandoc rendering:

New colon_grid format:

+------------+------------+------------+
| Column 1   | Column 2   | Column 3   |
+===========:+:===========+===========:+
| 1          | a          | 1.23       |
+------------+------------+------------+
| 2          | b          | 12.3       |
+------------+------------+------------+
| 3          | c          | 123        |
+------------+------------+------------+

Pandoc rendering of a colon_grid:

astanin commented Sep 26, 2024

Copy link
Copy Markdown
Owner

There is a extra empty line in the colon_grid doctests (tabulate/__init__.py:1865 and 1877).

Also the second doctest fails even when these empty lines are removed (there is no ':' in the first column).

_______________________________ [doctest] tabulate.tabulate _______________________________
1864     ...                ["strings", "numbers"], "colon_grid"))
1865     +-----------+-----------+
1866     | strings   | numbers   |
1867     +:==========+:==========+
1868     | spam      | 41.9999   |
1869     +-----------+-----------+
1870     | eggs      | 451       |
1871     +-----------+-----------+
1872
1873     >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
Differences (unified diff with -expected +actual):
    @@ -1,5 +1,5 @@
     +-----------+-----------+
     | strings   | numbers   |
    -+==========:+:==========+
    ++===========+:==========+
     | spam      | 41.9999   |
     +-----------+-----------+

...\python-tabulate\tabulate\__init__.py:1873: DocTestFailure

dn813 commented Sep 26, 2024

Copy link
Copy Markdown
Author

Thanks for pointing out the failing doctests, that's something I should have checked! Should be working now.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add new Pandoc grid table format

2 participants


Back | FazBrowse Home | New Git URL