From 3fdebf996200baf6dd7ee769488153afbf292b7b Mon Sep 17 00:00:00 2001 From: mecaneer23 Date: Mon, 29 Jan 2024 14:57:59 -0600 Subject: [PATCH] feature: determine how many trailing spaces to add or remove --- src/md_to_py.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/md_to_py.py b/src/md_to_py.py index c8672b4..a97ee4f 100644 --- a/src/md_to_py.py +++ b/src/md_to_py.py @@ -78,7 +78,10 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|") column_count = row.count(delimiter) - 1 if isinstance(widths, tuple) and len(widths) != column_count: - raise ValueError("`widths` cannot be a tuple of arbitrary length") + raise ValueError( + "`widths` cannot be a tuple of arbitrary length. "\ + f"Is {len(widths)}, should be {column_count}." + ) if isinstance(widths, int): widths = tuple(repeat(widths, column_count)) @@ -88,6 +91,7 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|") backward_count = 1 trailing_space_start = 0 prev_delimiter_index = 0 + change_amount = 0 new_row = "" while count < len(row): @@ -100,20 +104,19 @@ def _pad_columns(row: str, widths: tuple[int, ...] | int, delimiter: str = "|") widths[column] < non_space_len ): # maybe off by 1 error, as doesn't account for one trailing space raise ValueError( - f"Width of column `{column}` cannot be less than\ - {non_space_len}, is {widths[column]}" + f"Width of column `{column}` cannot be less than "\ + f"{non_space_len}, is {widths[column]}" ) prev_delimiter_index = count if widths[column] == non_space_len: backward_count = 1 count += 1 + column += 1 continue - if non_space_len + backward_count > widths[column]: - raise NotImplementedError("Make the amount of spaces smaller") - backward_count = 1 - continue - raise NotImplementedError("Make the amount of spaces larger") + change_amount = widths[column] - non_space_len - backward_count + 1 + print(f"change the amount of spaces by {change_amount}") backward_count = 1 + column += 1 count += 1 # - add or remove trailing spaces based on that value # (and the value of widths for that column)