Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ bacon 0
```

`github` follows the conventions of GitHub flavored Markdown. It
corresponds to the `pipe` format without alignment colons:
corresponds to the `pipe` format with the same alignment colons:

```pycon
>>> print(tabulate(table, headers, tablefmt="github"))
| item | qty |
|--------|-------|
|:-------|------:|
| spam | 42 |
| eggs | 451 |
| bacon | 0 |
Expand Down
14 changes: 4 additions & 10 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,6 @@ def escape_empty(val):
padding=1,
with_header_hide=None,
),
"github": TableFormat(
lineabove=Line("|", "-", "|", "|"),
linebelowheader=Line("|", "-", "|", "|"),
linebetweenrows=None,
linebelow=None,
headerrow=DataRow("|", "|", "|"),
datarow=DataRow("|", "|", "|"),
padding=1,
with_header_hide=["lineabove"],
),
"pipe": TableFormat(
lineabove=_pipe_line_with_colons,
linebelowheader=_pipe_line_with_colons,
Expand Down Expand Up @@ -720,6 +710,10 @@ def escape_empty(val):
),
}

# "github" is an alias for "pipe": both produce GitHub-flavored Markdown with
# alignment colons in the separator row.
_table_formats["github"] = _table_formats["pipe"]


tabulate_formats = sorted(_table_formats.keys())

Expand Down
47 changes: 43 additions & 4 deletions test/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ def test_simple_headerless_with_sep_line_with_padding_in_tablefmt():
"Output: simple without headers with sep line with padding in tablefmt"
expected = "\n".join(
[
"|------|----------|",
"|:-----|---------:|",
"| spam | 41.9999 |",
"|------|----------|",
"|:-----|---------:|",
"| eggs | 451 |",
]
)
Expand Down Expand Up @@ -487,7 +487,7 @@ def test_github():
expected = "\n".join(
[
"| strings | numbers |",
"|-----------|-----------|",
"|:----------|----------:|",
"| spam | 41.9999 |",
"| eggs | 451 |",
]
Expand All @@ -504,7 +504,7 @@ def test_github_multiline():
[
"| more | more spam |",
"| spam eggs | & eggs |",
"|-------------|-------------|",
"|------------:|:------------|",
"| 2 | foo |",
"| | bar |",
]
Expand All @@ -513,6 +513,45 @@ def test_github_multiline():
assert_equal(expected, result)


def test_github_with_colalign():
"Output: github with explicit column alignment"
expected = "\n".join(
[
"| Name | Age |",
"|:-------|------:|",
"| Alice | 24 |",
"| Bob | 19 |",
]
)
result = tabulate(
[["Alice", 24], ["Bob", 19]],
["Name", "Age"],
tablefmt="github",
colalign=("left", "right"),
)
assert_equal(expected, result)


def test_github_no_alignment():
"Output: github without alignment hints when numalign/stralign are disabled"
expected = "\n".join(
[
"| strings | numbers |",
"|-----------|-----------|",
"| spam | 41.9999 |",
"| eggs | 451 |",
]
)
result = tabulate(
_test_table,
_test_table_headers,
tablefmt="github",
numalign=None,
stralign=None,
)
assert_equal(expected, result)


def test_grid():
"Output: grid with headers"
expected = "\n".join(
Expand Down
Loading