Skip to content

Commit 95aaa4f

Browse files
committed
Add github flavored markdown support.
1 parent 433dfc6 commit 95aaa4f

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

README.rst

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Supported table formats are:
150150

151151
- "plain"
152152
- "simple"
153+
- "github"
153154
- "grid"
154155
- "fancy_grid"
155156
- "pipe"
@@ -188,6 +189,17 @@ extensions`_::
188189
eggs 451
189190
bacon 0
190191

192+
``github`` follows the conventions of `Github flavored Markdown`. It
193+
corresponds to the ``pipe`` format without alignment colons::
194+
195+
>>> print(tabulate(table, headers, tablefmt="github"))
196+
| item | qty |
197+
|--------|-------|
198+
| spam | 42 |
199+
| eggs | 451 |
200+
| bacon | 0 |
201+
202+
191203
``grid`` is like tables formatted by Emacs' `table.el`_
192204
package. It corresponds to ``grid_tables`` in Pandoc Markdown
193205
extensions::
@@ -527,6 +539,16 @@ a multiline cell, and headers with a multiline cell::
527539
more 42
528540
spam
529541

542+
``github`` tables::
543+
544+
>>> print(tabulate(table, headers, tablefmt="github"))
545+
| item | qty |
546+
| name | |
547+
|--------|-------|
548+
| eggs | 451 |
549+
| more | 42 |
550+
| spam | |
551+
530552
``grid`` tables::
531553

532554
>>> print(tabulate(table, headers, tablefmt="grid"))
@@ -638,8 +660,8 @@ Usage of the command line utility
638660
-s REGEXP, --sep REGEXP use a custom column separator (default: whitespace)
639661
-F FPFMT, --float FPFMT floating point number format (default: g)
640662
-f FMT, --format FMT set output table format; supported formats:
641-
plain, simple, grid, fancy_grid, pipe, orgtbl,
642-
rst, mediawiki, html, latex, latex_raw,
663+
plain, simple, github, grid, fancy_grid, pipe,
664+
orgtbl, rst, mediawiki, html, latex, latex_raw,
643665
latex_booktabs, tsv
644666
(default: simple)
645667

tabulate.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ def escape_empty(val):
253253
headerrow=DataRow("│", "│", "│"),
254254
datarow=DataRow("│", "│", "│"),
255255
padding=1, with_header_hide=None),
256+
"github":
257+
TableFormat(lineabove=Line("|", "-", "|", "|"),
258+
linebelowheader=Line("|", "-", "|", "|"),
259+
linebetweenrows=None,
260+
linebelow=None,
261+
headerrow=DataRow("|", "|", "|"),
262+
datarow=DataRow("|", "|", "|"),
263+
padding=1,
264+
with_header_hide=["lineabove"]),
256265
"pipe":
257266
TableFormat(lineabove=_pipe_line_with_colons,
258267
linebelowheader=_pipe_line_with_colons,

test/test_output.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ def test_simple_multiline_with_empty_cells_headerless():
191191
assert_equal(expected, result)
192192

193193

194+
def test_github():
195+
"Output: github with headers"
196+
expected = '\n'.join(['| strings | numbers |',
197+
'|-----------|-----------|',
198+
'| spam | 41.9999 |',
199+
'| eggs | 451 |',])
200+
result = tabulate(_test_table, _test_table_headers, tablefmt="github")
201+
assert_equal(expected, result)
202+
203+
194204
def test_grid():
195205
"Output: grid with headers"
196206
expected = '\n'.join(['+-----------+-----------+',

0 commit comments

Comments
 (0)