From bc3620adf956828562071f9feafc5923de567ea9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Thu, 19 Aug 2010 10:49:51 +0200 Subject: Add ability to remove all empty columns automatically. --- src/rst_tables.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/rst_tables.py') diff --git a/src/rst_tables.py b/src/rst_tables.py index 1cceb91..695d5bd 100644 --- a/src/rst_tables.py +++ b/src/rst_tables.py @@ -27,12 +27,30 @@ def get_table_bounds(): def unify_table(table): max_fields = max(map(lambda row: len(row), table)) + empty_cols = [True] * max_fields output = [] for row in table: curr_len = len(row) if curr_len < max_fields: row += [''] * (max_fields - curr_len) output.append(row) + + # register empty columns (to be removed at the end) + for i in range(len(row)): + if row[i].strip(): + empty_cols[i] = False + + # remove empty columns from all rows + table = output + output = [] + for row in table: + cols = [] + for i in range(len(row)): + should_remove = empty_cols[i] + if not should_remove: + cols.append(row[i]) + output.append(cols) + return output -- cgit v1.2.3