From ed1031a67cec93063af96173ab685827426dc806 Mon Sep 17 00:00:00 2001 From: Matthias Diener <mdiener@illinois.edu> Date: Mon, 24 Aug 2020 22:34:38 -0500 Subject: [PATCH] add doc and doctest --- pytools/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pytools/__init__.py b/pytools/__init__.py index 6c8e358..fd915f3 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -1513,6 +1513,21 @@ class Table: return "\n".join(lines) def github_markdown(self): + """Returns a string representation of the table formatted as + GitHub-Flavored Markdown. + https://docs.github.com/en/github/writing-on-github/organizing-information-with-tables + + .. doctest :: + + >>> tbl = Table(alignments=['l', 'r']) + >>> tbl.add_row([1, 2]) + >>> tbl.add_row([10, 20]) + >>> s = tbl.github_markdown().splitlines() + >>> assert s[0] == "1 | 2" + >>> assert s[1] == ":--|---:" + >>> assert s[2] == "10 | 20" + + """ columns = len(self.rows[0]) col_widths = [max(len(row[i]) for row in self.rows) for i in range(columns)] -- GitLab